题意 :
给你个箱子,然后n个隔板把箱子分成 n+1各区域。
然后给你最后玩具的具体位置坐标。而且保证玩具不会在隔板上也不会在箱子外面。
个上一题的区别是这次问你放了多少个玩具的区间分别是多少个。
题解:
和上题一样,加个标记数组就可以了,
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#define x first
#define y second
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//#include<ext/pb_ds/hash_policy.hpp>
using namespace std;
const int maxn=5005;
int n,m,x1,y1,x2,y2,t1,t2;
pair<int,int> p[maxn];
int v[maxn];
bool cmp(pair<int,int> a,pair<int,int> b){
return a.x<b.x;
}
int judge(int t,int a,int b){
if(p[t].x==p[t].y){
return a>=p[t].y;
}else {
int ret=(a-p[t].x)*(y2-y1)-(b-y1)*(p[t].y-p[t].x);
return ret<0;
}
}
int ans[maxn];
int main(){
while(scanf("%d",&n)&&n){
memset(v,0,sizeof(v));
memset(ans,0,sizeof(ans));
scanf("%d %d %d %d %d",&m,&x1,&y1,&x2,&y2);
for(int i=1;i<=n;++i)
scanf("%d %d",&p[i].x,&p[i].y);
sort(p+1,p+1+n,cmp);
p[0].x=p[0].y=min(x1,y1);
p[n+1].x=p[n+1].y=max(x2,y2);
for(int i=1;i<=m;++i){
scanf("%d %d",&t1,&t2);
int l=0,r=n+1;
while(l<=r){
int mid=(l+r)/2;
if(judge(mid,t1,t2)) l=mid+1;
else r=mid-1;
}
v[l-1]++;
}
int cnt=0;
puts("Box");
for(int i=0;i<=n;++i) if(v[i]) ans[v[i]]++;
for(int i=0;i<maxn;++i) if(ans[i]) printf("%d: %d\n",i,ans[i]);
//puts("");
}
return 0;
}