水题
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
struct node
{
double k;
double b;
}par[5005];
int num[5005];
int n,m;
double x1=0,x2=0,y1=0,y2=0;
int search(int begin,int end,double x,double y)
{
int m=(end+begin)/2;
double s1,s2;
if(m==0)
s1=x1;
else
s1=par[m].k*y+par[m].b;
if(m==n)
s2=x2;
else
s2=par[m+1].k*y+par[m+1].b;
if(x>s1&&x<s2)
return m;
if(x>s2)
return search(m+1,end,x,y);
if(x<s1)
return search(begin,m-1,x,y);
return 1000;
}
int main()
{
freopen("test.txt","r",stdin);
int i;
double Ui=0,Li=0;
double xj=0,yj=0;
int position;
while(scanf("%d",&n)!=EOF && n!=0 )
{
scanf("%d %lf %lf %lf %lf",&m,&x1,&y1,&x2,&y2);
for(i=1;i<=n;i++)
{
scanf("%lf %lf",&Ui,&Li);
par[i].k=(Ui-Li)/(y1-y2);
par[i].b=Ui-y1*(par[i].k);
}
memset(num,0,sizeof(num));
for(i=1;i<=m;i++)
{
scanf("%lf %lf",&xj,&yj);
position=search(0,n,xj,yj);
num[position]++;
}
for(i=0;i<=n;i++)
printf("%d: %d\n",i,num[i]);
printf("\n");
}
return 0;
}