POJ 2398 Toy Storage
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; #define Max 2000 using namespace std; struct Node { int x,y; }point1[Max],point2[Max],high,low,tmp; int n,tm[Max],ans[Max]; bool cmp(Node a,Node b) { if(a.x<b.x)return true; return false; } int cal(Node a,Node b,Node c) //cb*ca { if((b.x-c.x)*(a.y-c.y)-(a.x-c.x)*(b.y-c.y)>0) return 1; return 0; } int search() { int l=0,r=n-1,mid; while(l<=r) { mid=(l+r)>>1; if(cal(point2[mid],point1[mid],tmp)) l=mid+1; else r=mid-1; } tm[l]++; return 0; } int main() { int i,m; while(scanf("%d",&n)!=EOF&&n!=0) { memset(tm,0,sizeof(tm)); memset(ans,0,sizeof(ans)); scanf("%d%d%d%d%d",&m,&high.x,&high.y,&low.x,&low.y); for(i=0;i<n;i++) { scanf("%d %d",&point1[i].x,&point2[i].x); point1[i].y=high.y; point2[i].y=low.y; } sort(point1,point1+n,cmp); sort(point2,point2+n,cmp); for(i=0;i<m;i++) { scanf("%d%d",&tmp.x,&tmp.y); search(); } //sort(tm,tm+m); printf("Box\n"); for(i=0;i<=n;i++) { if(tm[i]) ans[tm[i]]++; } for(i=0;i<m;i++) { if(ans[i]) printf("%d: %d\n",i,ans[i]); } } return 0; }