对线段排完序直接二分
对叉积的解释之后会贴上连接
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<iostream>
using namespace std;
struct point
{
int x,y;
point(){
}
point(int a,int b)
{
x=a,y=b;
}
point operator- (const point b) const
{
return point(x-b.x,y-b.y);
}
int operator^ (const point b) const
{
return x*b.y-y*b.x;
}
};
struct line
{
point x,y;
line(){
}
line(point a,point b)
{
x=a,y=b;
}
}li[1100];
bool cmp(line a,line b)
{
return a.x.x<b.x.x;
}
int x_(point x0,point x1,point x2)
{
return (x1-x0)^(x2-x0);
}
int ans[1200];
int num[1200];
int main()
{
int n;
while(scanf("%d",&n),n)
{
int m,x1,y1,x2,y2;
int Ui,Li;
scanf("%d%d%d%d%d",&m,&x1,&y1,&x2,&y2);
for(int i=0;i<n;i++)
{
scanf("%d%d",&Ui,&Li);
li[i]=line(point(Ui,y1),point(Li,y2));
}
li[n]=line(point(x2,y1),point(x2,y2));
sort(li,li+n+1,cmp);
int x,y;
memset(ans,0,sizeof(ans));
while(m--)
{
scanf("%d%d",&x,&y);
point p;
p=point(x,y);
int temp=0,l=0,r=n;
while(r>=l)
{
int mid=(r+l)/2;
if(x_(p,li[mid].x,li[mid].y)<0)
{
temp=mid;
r=mid-1;
}
else
{
l=mid+1;
}
}
ans[temp]+=1;
}
for(int i = 1;i <= n;i++)
num[i] = 0;
for(int i = 0;i <= n;i++)
if(ans[i]>0)
num[ans[i]]++;
printf("Box\n");
for(int i = 1;i <= n;i++)
if(num[i]>0)
printf("%d: %d\n",i,num[i]);
}
}