题目描述:
跟上一题差不多,只是隔板是乱序的,最后输出的是装有 i 个玩具区域的个数
题目链接:
AC Code:
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
struct Point{
double x,y;
};
struct line{
Point up,down;
};
int n,m,ans[5005];
line li[5005];
int cnt[5005];
bool Cross_product(Point p0,Point p1,Point p2)
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y)>0;
}
int judge(Point p)
{
int l=1,r=n+1;
int ans=0;
while(l<=r)
{
int mid=(l+r)>>1;
if(!Cross_product(li[mid].down,p,li[mid].up)) ans=mid,r=mid-1;
else l=mid+1;
}
return l;
}
bool comp(line l1,line l2)
{
return l1.up.x<l2.up.x;
}
int main()
{
Point lu,rd;
while(scanf("%d",&n))
{
if(!n) break;
scanf("%d%lf%lf%lf%lf",&m,&lu.x,&lu.y,&rd.x,&rd.y);
for(int i=1;i<=n;i++)
{
scanf("%lf%lf",&li[i].up.x,&li[i].down.x);
li[i].up.y=lu.y;
li[i].down.y=rd.y;
ans[i]=0;
}
li[n+1].up.x=rd.x,li[n+1].up.y=lu.y;
li[n+1].down=rd;
ans[n+1]=0;
sort(li+1,li+n+2,comp);
for(int i=1;i<=m;i++)
{
cnt[i]=0;
Point p;
scanf("%lf%lf",&p.x,&p.y);
if(!(rd.y<=p.y&&p.y<=lu.y&&lu.x<=p.x&&p.x<=rd.x)) continue;
ans[judge(p)]++;
}
puts("Box");
for(int i=1;i<=n+1;i++)
cnt[ans[i]]++;
for(int i=1;i<=m;i++)
if(cnt[i])
printf("%d: %d\n",i,cnt[i]);
}
return 0;
}