POJ 2318 TOYS
蒻苣:弱弱很弱,路过的巨巨还不吝赐教!^.^...QAQ
题意:给一个长方形,中间隔着n个板,分成n+1个区域,给出m个点,问每个区域有多少个点在里面。
题解:第一道计算几何。也算入门题吧。暴力叉乘即可。可能数据水了 314ms过的,数据大点的话,可以加个二分。
值得注意的地方就是冒号后面有个空格。
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 using namespace std; 7 const double INF = 1E200; 8 const double EP = 1E-10; 9 const int MAXV = 300; 10 int sum[5000+50]; 11 struct POINT{ 12 int x,y; 13 POINT(int a = 0,int b = 0){x = a, y = b;} 14 }; 15 POINT s[5000+50]; 16 struct LINESEG{ 17 POINT s; 18 POINT e; 19 LINESEG(POINT a,POINT b){s = a;e = b;} 20 LINESEG(){} 21 }; 22 LINESEG t[5000+50]; 23 int multiply(POINT sp,POINT ep,POINT op) 24 { 25 return ( ( sp.x - op.x ) * ( ep.y - op.y ) - ( ep.x - op.x ) * ( sp.y - op.y ) ); 26 } 27 int main() { 28 int n,m,x1,y1,x2,y2; 29 while(~scanf("%d",&n)&&n) 30 { 31 memset(sum,0,sizeof(sum)); 32 scanf("%d%d%d%d%d",&m,&x1,&y1,&x2,&y2); 33 int x,y; 34 for(int i = 1;i <= n;i++) 35 { 36 scanf("%d%d",&t[i].e.x,&t[i].s.x); 37 t[i].e.y = y1; 38 t[i].s.y = y2; 39 } 40 for(int i = 0;i<m;i++) scanf("%d%d",&s[i].x,&s[i].y); 41 for(int i = 0;i<m;i++) 42 { 43 int flag = 0; 44 for(int j = 1;j<=n;j++) 45 { 46 if(multiply(t[j].e ,s[i] ,t[j].s ) >= 0) 47 { 48 flag = j; 49 break; 50 } 51 } 52 if(flag==0) sum[n+1]++; 53 else sum[flag]++; 54 } 55 for(int i = 1;i <= n+1; i++) 56 printf("%d: %d\n",i-1,sum[i]); 57 printf("\n"); 58 } 59 return 0; 60 }
浙公网安备 33010602011771号