POJ 2318 TOYS
#include<stdio.h> #include<string.h> #define Max 5010 struct node { int x,y; }low[Max],high[Max]; node a,b; int n,m; int cal(node aa,node bb,node cc) { //return (cc.x-aa.x)*(bb.y-aa.y)-(cc.y-aa.y)*(bb.x-aa.x);//第一种 return (bb.x-cc.x)*(aa.y-cc.y)-(bb.y-cc.y)*(aa.x-cc.x);//第二种 } int solve(node cc) { int l,r,mid; l=0;r=n-1; while(l<=r) { mid=(l+r)>>1; if(cal(low[mid],high[mid],cc)>0) l=mid+1; else r=mid-1; } return l; } int num[Max]; int main() { int i; while(scanf("%d",&n)!=EOF&&n!=0) { scanf("%d%d%d%d%d",&m,&a.x,&a.y,&b.x,&b.y); for(i=0;i<n;i++) { scanf("%d %d",&high[i].x,&low[i].x); high[i].y=a.y; low[i].y=b.y; } low[n].x=b.x; low[n].y=b.y; high[n].x=a.x; high[n].y=a.y; node temp; memset(num,0,sizeof(num)); while(m--) { scanf("%d %d",&temp.x,&temp.y); int pos=solve(temp); num[pos]++; } for(i=0;i<=n;i++) printf("%d: %d\n",i,num[i]); printf("\n"); } return 0; }