这道题目和上一道真是姐妹题目啊!就是多了一个排序,因为2318这题已经排好序了,而这题是没有排好序的!
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1005;
int num[maxn];
int n,m;
struct point
{
double x;
double y;
};
struct line
{
point high,low;
}L[maxn];
bool cmp(const line &m1,const line &m2)
{
if(m1.high.x==m2.high.x)
return m1.low.x<m2.low.x;
else
return m1.high.x<m2.high.x;
}
double pp(const point &aa,const point &bb,const point &cc)
{
return (cc.x-bb.x)*(aa.y-bb.y)-(cc.y-bb.y)*(aa.x-bb.x);
}
int solve(point &cc)
{
int l=0;
int r=n;
while(l<r)
{
int mid=(l+r)>>1;
if(pp(L[mid].high, L[mid].low, cc)>0)
{
l=mid+1;
}
else
{
r=mid;
}
}
return l;
}
int main()
{
int i;
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
while(scanf("%d",&n),n)
{
double a_x,a_y,b_x,b_y;
scanf("%d%lf%lf%lf%lf",&m,&a_x,&a_y,&b_x,&b_y);
for(i=0; i<n; i++)
{
scanf("%lf%lf",&L[i].high.x,&L[i].low.x);
L[i].high.y=a_y;
L[i].low.y=b_y;
}
L[n].high.x=b_x;L[n].high.y=a_y;
L[n].low.x=b_x;L[n].low.y=b_y;
sort(L,L+n+1,cmp);
point temp;
memset(num,0,sizeof(num));
for(i=0; i<m; i++)
{
scanf("%lf%lf",&temp.x,&temp.y);
int k;
k=solve(temp);
num[k]++;
}
sort(num,num+n+1);
int sum;
int z=0;
printf("Box\n");
for(i=0; i<=n; i++)
{
if(num[i]>z)
{
if(z!=0)
{
printf("%d\n",sum);
}
sum=1;
z=num[i];
printf("%d: ",z);
}
else
sum++;
}
if(z!=0)
printf("%d\n",sum);
}
return 0;
}