[ An Ac a Day ^_^ ] CodeForces 659D Bicycle Race 计算几何 叉积

时间:2022-05-01 18:12:44

问有多少个点在多边形内

求一遍叉积 小于零计数就好了~

 #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>
#define M(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
struct point{
int x,y;
}pnt[];
int solve(point a,point b,point c){
return (b.x-a.x)*(c.y-b.y)-(c.x-b.x)*(b.y-a.y);
}
int main(){
int n;
scanf("%d",&n);
n++;
for(int i=;i<n;i++)
scanf("%d%d",&pnt[i].x,&pnt[i].y);
int ans=;
for(int i=;i<n;i++)
if(solve(pnt[i-],pnt[i-],pnt[i])>) ans++;
printf("%d\n",ans);
return ;
}
/* 6
0 0
0 1
1 1
1 2
2 2
2 0
0 0 16
1 1
1 5
3 5
3 7
2 7
2 9
6 9
6 7
5 7
5 3
4 3
4 4
3 4
3 2
5 2
5 1
1 1 */