问有多少个点在多边形内
求一遍叉积 小于零计数就好了~
1 #include<stdio.h> 2 #include<iostream> 3 #include<algorithm> 4 #include<math.h> 5 #include<string.h> 6 #include<string> 7 #include<map> 8 #include<set> 9 #include<vector> 10 #include<queue> 11 #define M(a,b) memset(a,b,sizeof(a)) 12 using namespace std; 13 typedef long long ll; 14 struct point{ 15 int x,y; 16 }pnt[1005]; 17 int solve(point a,point b,point c){ 18 return (b.x-a.x)*(c.y-b.y)-(c.x-b.x)*(b.y-a.y); 19 } 20 int main(){ 21 int n; 22 scanf("%d",&n); 23 n++; 24 for(int i=0;i<n;i++) 25 scanf("%d%d",&pnt[i].x,&pnt[i].y); 26 int ans=0; 27 for(int i=2;i<n;i++) 28 if(solve(pnt[i-2],pnt[i-1],pnt[i])>0) ans++; 29 printf("%d ",ans); 30 return 0; 31 } 32 /* 33 34 6 35 0 0 36 0 1 37 1 1 38 1 2 39 2 2 40 2 0 41 0 0 42 43 16 44 1 1 45 1 5 46 3 5 47 3 7 48 2 7 49 2 9 50 6 9 51 6 7 52 5 7 53 5 3 54 4 3 55 4 4 56 3 4 57 3 2 58 5 2 59 5 1 60 1 1 61 62 */