The computational geometry finally opened the hole ...
Cross product + two points.
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#defineMAXN 5050using namespacestd;structpoint{intx, y; Point (intXinty): x (x), Y (y) {} point () {} friend pointoperator-(point X,point y) {returnPoint (x.x-y.x,x.y-y.y); }}P[MAXN];structline{Point X,dt; Line (point X,point DT): X (x), dt (DT) {} line () {} friendint operator*(line X,line y) {returnx.dt.x*y.dt.y-y.dt.x*X.dt.y; }}L[MAXN];intn,m,cnt[maxn],x1,y1,x2,y2,x,y;BOOLCheckintXS) {return(Line (L[xs].x,point (x, y)-l[xs].x) *l[xs]) >=0;}intAsk () {intL=0, r=n,ans=-1; while(l<=r) {intMid= (l+r) >>1; if(Check (mid)) {ans=mid;l=mid+1;} Elser=mid-1; } returnans;}intMain () { for (;;) {scanf ("%d", &n);if(!n) Break; scanf ("%d",&m); scanf ("%d%d%d%d",&x1,&y2,&x2,&y1); memset (CNT,0,sizeof(CNT)); l[0]=line (Point (X1,y1), point (0, y2-y1)); for(intI=1; i<=n;i++) {scanf ("%d%d",&x,&y); L[i]=line (Point (Y,y1), point (x-y,y2-y1)); } l[n+1]=line (Point (X2,y1), point (0, y2-y1)); for(intI=1; i<=m;i++) {scanf ("%d%d",&x,&y); Cnt[ask ()]++; } for(intI=0; i<=n;i++) printf ("%d:%d\n", I,cnt[i]); printf ("\ n"); } return 0;}
POJ 2318 toys/poj 2398 Toy Storage