[poj2398]Toy Storage
接替关键:和上题类似,输出不同,注意输入这道题需要排序。
#include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #include<cmath> #include<iostream> using namespace std; typedef long long ll; struct point{ int x,y; }; int n,m,x1,x2,y11,y2; struct Line{ point a,b; }A[5010]; double operator*(point p1,point p2){return p1.x*p2.y-p2.x*p1.y;} point operator-(point A,point B){return {A.x-B.x,A.y-B.y};} int pos[5010]; bool judge(point t,int mid){//叉积 point tt=A[mid].b-A[mid].a; int ans=tt*(t-A[mid].a); return ans<0; } bool cmp(Line a,Line b){ return a.a.x<b.a.x; } int erfen(point xx){ int l=0,r=n; while(l<r){ int mid=(l+r)>>1; if(judge(xx,mid)) r=mid; else l=mid+1; } return r; } int num[1002]; int main(){ while(scanf("%d",&n)!=EOF&&n){ scanf("%d%d%d%d%d",&m,&x1,&y11,&x2,&y2); for(int i=0;i<n;i++){ int xd,xu; scanf("%d%d",&xu,&xd); A[i]={{xu,y11},{xd,y2}}; } sort(A,A+n,cmp); memset(pos,0,sizeof pos); for(int i=0;i<m;i++){ int xx,yy; scanf("%d%d",&xx,&yy); point t={xx,yy}; int ans=erfen(t); pos[ans]++; } memset(num,0,sizeof num); for(int i=0;i<=1000;i++){ if(pos[i]) num[pos[i]]++; } printf("Box\n"); for(int i=1;i<=1000;i++){ if(!num[i]) continue; printf("%d: %d\n",i,num[i]); } } return 0; }