题意:有一个大箱子,由n个板分为n+1块,标号为0~n
已知盒子左上角和右下角的坐标及每个板上下两端的横坐标(板不会交错,且按顺序给出)
然后给出玩具的坐标,统计每块空间内玩具个数(保证玩具一定落在空间内)
方法:叉积+二分,判断点所在的空间
//============================================================================
// Name : 2318.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
#define MAX 5011
int s[MAX],n,m,x1,x2,y1,y2,sum[MAX],xp[MAX],xd[MAX];
struct point{
int x,y;
}p[MAX],t1,t2,key;
int Xmult(point a,point b,point c){
return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
}
void binarySearch(point idx){
int l=0,r=n,mid;
while(l<=r){
mid=(l+r)>>1;
t1.x=xp[mid];
t2.x=xd[mid];
if(Xmult(t1,t2,idx)<0) r=mid-1;
else l=mid+1;
}
sum[l-1]++;
}
int main() {
while(scanf("%d",&n),n){
cin>>m>>x1>>y1>>x2>>y2;
xp[0]=xd[0]=x1;t1.y=y1;t2.y=y2;
for(int i=1;i<=n;i++){
cin>>xp[i]>>xd[i];
}
memset(sum,0,sizeof(sum));
for(int j=1;j<=m;j++){
cin>>p[j].x>>p[j].y;
binarySearch(p[j]);
}
for(int j=0;j<=n;j++){
cout<<j<<": "<<sum[j]<<endl;
}
cout<<endl;
}
return 0;
}