Reza's parents came up with the following idea. They put cardboard partitions into the box. Even if Reza keeps throwing his toys into the box, at least toys that get thrown into different partitions stay separate. The box looks like this from the top:
We want for each positive integer t, such that there exists a partition with t toys, determine how many partitions have t, toys.
A line consisting of a single 0 terminates the input.
4 10 0 10 100 0 20 20 80 80 60 60 40 40 5 10 15 10 95 10 25 10 65 10 75 10 35 10 45 10 55 10 85 10 5 6 0 10 60 0 4 3 15 30 3 1 6 8 10 10 2 1 2 8 1 5 5 5 40 10 7 9 0
Box 2: 5 Box 1: 4 2: 1
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
#define INF 0x3f3f3f3f
#define CVector CPoint
typedef long long LL;
double PI=acos(-1);
double ESP=1e-6;
struct CPoint{
double x,y;
CPoint(double xx,double yy):x(xx),y(yy){}
CPoint(){}
};
struct CLine{
CPoint a,b;
CLine(CPoint aa,CPoint bb):a(aa),b(bb){}
CLine(){}
};
CPoint operator +(CPoint a,CPoint b){
return CPoint(a.x+b.x,a.y+b.y);
}//c=a+b
CPoint operator -(CPoint a,CPoint b){
return CPoint(a.x-b.x,a.y-b.y);
}//c=a-b
CPoint operator *(CPoint a,double k){
return CPoint(k*a.x,k*a.y);
}//c=k*a;
CPoint operator *(double k,CPoint a){
return CPoint(k*a.x,k*a.y);
}//c=k*a
double operator *(CPoint a,CPoint b){
return a.x*b.x+a.y*b.y;
}//c=a*b 点击
double operator ^(CPoint a,CPoint b){
return a.x*b.y-a.y*b.x;
}//叉积
double Length(CVector p){
return sqrt(p*p);
}//求长度
CVector unit(CVector p){
return 1.0/Length(p)*p;
}//求p方向单位向量
double project(CVector p,CVector n){
return p*(unit(n));
}//求p在n方向上投影长度
double area(CVector a,CVector b){
return a^b*0.5;
}//求a,b所夹的有向面积
bool isZero(double x){
return -ESP<x&&x<ESP;
}//判断是否为0
double dist(CPoint p,CPoint q){
return Length(p-q);
}//求两点间距离
double dist(CPoint p,CLine l){
return fabs((p-l.a)^(p-l.b))/Length(l.a-l.b);
}//求点到线的距离
CPoint Rotate(CPoint a,CPoint b,double alpha){
CVector p=b-a;
return CPoint(a.x+(p.x*cos(alpha)
-p.y*sin(alpha)),
a.y+(p.x*sin(alpha)
+p.y*cos(alpha)));
}//b绕a逆时针旋转alpha
int sideOfLine(CPoint p,CLine l){
double res=(p-l.a)^(p-l.b);
if(isZero(res)){
return 0;
}else{
return res>0? 1:-1;
}
}//判断点和直线关系,0-直线上,1-左,-1-右
CLine Vertical(CPoint p,CLine l){
return CLine(p,p+(Rotate(l.b,l.a,PI/2)-l.a));
}//求过p的l的垂线
CPoint root(CPoint p,CLine l){
return l.a+project(p-l.a,l.b-l.a)*unit(l.b-l.a);
}//垂足
double angle(CLine l,CLine m){
return acos(fabs(
project(l.b-l.a,m.b-m.a)
/Length(l.b-l.a)));
}//两直线夹角
CLine s[1005];
int num[1005],cnt[1005];
bool cmp(CLine a,CLine b){
return a.a.x<b.a.x&&a.b.x<b.b.x;
}
int main()
{
int n,m;
double x1,x2,y1,y2;
while(~scanf("%d",&n),n){
int maxn=0;
scanf("%d%lf%lf%lf%lf",&m,&x1,&y1,&x2,&y2);
memset(num,0,sizeof(num));
memset(cnt,0,sizeof(cnt));
s[0].a=CPoint(x1,y1);
s[0].b=CPoint(x1,y2);
for(int i=1;i<=n;i++){
double x_1,x_2;
scanf("%lf%lf",&x_1,&x_2);
s[i].a=CPoint(x_1,y1);
s[i].b=CPoint(x_2,y2);
}
sort(s+1,s+1+n,cmp);
s[n+1].a=CPoint(x2,y1);
s[n+1].b=CPoint(x2,y2);
while(m--){
double x,y;
scanf("%lf%lf",&x,&y);
CPoint temp(x,y);
int l=0,r=n+1;
int _m=(l+r)/2;
while(r-l>1){
if(sideOfLine(temp,s[_m])==-1){
r=_m;
}else{
l=_m;
}
_m=(l+r)/2;
}
if(num[_m]){
cnt[num[_m]]--;
}
num[_m]++;
cnt[num[_m]]++;
maxn=max(maxn,num[_m]);
}
printf("Box\n");
for(int i=1;i<=maxn;i++){
if(cnt[i]){
printf("%d: %d\n",i,cnt[i]);
}
}
}
return 0;
}
492



被折叠的 条评论
为什么被折叠?



