bzoj 1043 [HAOI2008]下落的圆盘



1043: [HAOI2008]下落的圆盘

Time Limit: 10 Sec   Memory Limit: 162 MB
Submit: 1407   Solved: 591
[ Submit][ Status][ Discuss]

Description

  有n个圆盘从天而降,后面落下的可以盖住前面的。求最后形成的封闭区域的周长。看下面这副图, 所有的红
色线条的总长度即为所求.

Input

  第一行为1个整数n,N<=1000
接下来n行每行3个实数,ri,xi,yi,表示下落时第i个圆盘的半径和圆心坐标.

Output

  最后的周长,保留三位小数

Sample Input

2
1 0 0
1 1 0

Sample Output

10.472

HINT

Source




【分析】

N^2判断+贪心线段覆盖

需要用到acos,atan2之类的函数(具体不解释咯)


ps:注意前面的圆被后面的圆完全覆盖的情况!




【代码】

//bzoj 1043 [HAOI2008]下落的圆盘
#include<cmath>
#include<cstdio>
#include<iostream>
#include<algorithm>
#define eps 1e-8
#define pi acos(-1)
#define fo(i,j,k) for(i=j;i<=k;i++)
using namespace std;
const int mxn=1005;
double ans;
int n,m,top;
struct angle {double l,r;} s[mxn];
struct circle {double r,x,y;} c[mxn];
inline bool comp(angle x,angle y)
{
	if(x.l==y.l) return x.r<y.r;
	return x.l<y.l;
}
inline double dis(circle c1,circle c2)
{
	return sqrt((c1.x-c2.x)*(c1.x-c2.x)+(c1.y-c2.y)*(c1.y-c2.y));
}
inline bool contain(circle c1,circle c2)
{
	return dis(c1,c2)+c2.r<=c1.r || c1.r+c2.r<=dis(c1,c2);
}
int main()
{
	int i,j;
	scanf("%d",&n);
	fo(i,1,n)
	  scanf("%lf%lf%lf",&c[i].r,&c[i].x,&c[i].y);
	fo(i,1,n)
	{
		fo(j,i+1,n) if(dis(c[i],c[j])+c[i].r<=c[j].r) break;
		if(j!=n+1) continue;
		top=0;
		fo(j,i+1,n)
		{
			if(contain(c[i],c[j])) continue;
			double k=atan2(c[j].y-c[i].y,c[j].x-c[i].x);
			double A=dis(c[i],c[j]),B=c[i].r,C=c[j].r;
			double ang=acos((A*A+B*B-C*C)/(2*A*B));
			double l1=k-ang,l2=k+ang;
			if(l1<0) l1+=2*pi;
			if(l2<0) l2+=2*pi;
			if(l1<=l2) s[++top]=(angle){l1,l2};
			else s[++top]=(angle){l1,2*pi},s[++top]=(angle){0,l2};
		}
		sort(s+1,s+top+1,comp);
		double now=0,tmp=0;
		fo(j,1,top)
		{
			double t1=s[j].l,t2=s[j].r;
			if(t1>now) tmp+=t1-now,now=t2;
			else now=max(now,t2);
		}
		tmp+=2*pi-now;
		ans+=tmp*c[i].r;
	}
	printf("%.3lf\n",ans);
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值