二分
#include <iostream> using namespace std; const int maxn=5010; int Ui[maxn],Li[maxn],dx[maxn],dy; int amount[maxn]; int m,n,x1,y1,x2,y2; int bsearch(int xj,int yj) { int low=-1,high=m,mid; while(high-low>1) { mid=(high+low)/2; if((dy*(xj-Ui[mid])-dx[mid]*(yj-y1))<0) high=mid; else low=mid; } return high; } int main() { while(scanf("%d",&m)&&m!=0) { cin>>n>>x1>>y1>>x2>>y2; dy=y1-y2; int i; for(i=0;i<m;i++) { cin>>Ui[i]>>Li[i]; dx[i]=Ui[i]-Li[i]; amount[i]=0; } amount[i]=0; int xj,yj,outcome; for(i=0;i<n;i++) { cin>>xj>>yj; outcome=bsearch(xj,yj); amount[outcome]++; } for(i=0;i<=m;i++) { cout<<i<<": "<<amount[i]<<endl; } cout<<endl; } return 0; }