这个和2318差不多,就是纸板给的不是按顺序了,要自己排个序,然后结果是得输出盒子里面玩具的个数,空的就不用输了。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct coor{
int a,b,c,d;
}p[5005];
int n,m;
int judge(int x,int y,int i){
return (x-p[i].c)*(p[i].b-p[i].d)-(p[i].a-p[i].c)*(y-p[i].d);
}
int cmp(coor A,coor B){
if(A.a==B.c)return A.c<B.c;
else return A.a<B.a;
}
int bsearch(int x,int y){
int l=0,r=n-1;
while(l<r){
int mid=l+(r-l)/2;
if(judge(x,y,mid)>0)l=mid+1;
else r=mid;
}
if(judge(x,y,l)>0)return l+1;
else return l;
}
int main(){
int x1,x2,y1,y2;
int sum[5005];
while(scanf("%d",&n)==1&&n){
memset(sum,0,sizeof(sum));
scanf("%d %d %d %d %d",&m,&x1,&y1,&x2,&y2);
for(int i=0;i<n;i++){
scanf("%d %d",&p[i].a,&p[i].c);
p[i].b=y1, p[i].d=y2;
}
sort(p,p+n,cmp);
for(int i=0;i<m;i++){
int x,y,pos;
scanf("%d %d",&x,&y);
pos=bsearch(x,y);
sum[pos]++;
}
printf("Box\n");
sort(sum,sum+n+1);
int t,ans;
for(int i=0;i<=n;i++)if(sum[i]!=0){
t=sum[i],ans=0;
while(t==sum[i])
{ i++,ans++; }
printf("%d: %d\n",t,ans);
i--;
}
}
return 0;
}