BZOJ 1043 下落的圆盘
Description
有n个圆盘从天而降,后面落下的可以盖住前面的。求最后形成的封闭区域的周长。看下面这副图, 所有的红色线条的总长度即为所求. 
Input
n ri xi y1 ... rn xn yn
Output
最后的周长,保留三位小数
Sample Input
1 0 0
1 1 0
Sample Output
HINT
数据规模
n<=1000


#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
using namespace std; #define pi (3.1415926535)
#define esp (1e-6)
#define maxn 2010
int n; double ans; inline bool equal(double a,double b) { return fabs(a - b) < esp; } inline double qua(double a) { return a * a; } inline bool dd(double a,double b) { if (equal(a,b)) return true; return a >= b; } //>= inline bool xd(double a,double b) { if (equal(a,b)) return true; return a <= b; } //<= struct NODE{ double x,y; };
struct angle
{
double a1,a2;
friend inline bool operator < (angle a,angle b)
{
if (!equal(a.a1,b.a1)) return xd(a.a1,b.a1);
return xd(a.a2,b.a2);
}
}bac[maxn];
struct CIR
{
double r,x,y;
inline void read() { scanf("%lf %lf %lf",&r,&x,&y); }
inline NODE mid() { return (NODE) {x,y}; }
inline double calc(NODE p) { return atan2(p.y-y,p.x-x); }
inline double C() { return *pi*r; }
}cir[maxn];
struct LINE
{
double a,b,c;
inline double dis(NODE p) { return fabs(a*p.x+b*p.y+c)/sqrt(qua(a)+qua(b)); }
inline double key(NODE p) { return p.x*a+p.y*b+c; }
}; inline double dis(NODE a,NODE b) { return sqrt(qua(a.x-b.x) + qua(a.y-b.y)); } inline bool have(CIR c1,CIR c2) { return dis(c1.mid(),c2.mid())<c1.r+c2.r; } inline bool cat(CIR c1,CIR c2) { return xd(dis(c1.mid(),c2.mid()),fabs(c1.r-c2.r)); } inline LINE cross(CIR c1,CIR c2) { return (LINE) {*(c2.x-c1.x),*(c2.y-c1.y),(qua(c2.r)-qua(c2.x)-qua(c2.y))-(qua(c1.r)-qua(c1.x)-qua(c1.y))}; } inline void work()
{
int tot,i,j; double rest,p,q,a,b,now; LINE l;
for (i = n;i;--i)
{
tot = ; rest = ; now = ;
for (j = i+;j <= n;++j)
{
if (cat(cir[i],cir[j]))
{
if (cir[i].r > cir[j].r) continue;
else break;
}
if (have(cir[i],cir[j]))
{
p = cir[i].calc(cir[j].mid()) + pi;
l = cross(cir[i],cir[j]);
q = l.dis(cir[i].mid());
q = acos(q/cir[i].r);
if (cir[i].r < cir[j].r&&l.key(cir[i].mid())*l.key(cir[j].mid()) > )
q = pi - q;
a = p - q; b = p + q;
if (dd(a,) && xd(b,*pi))
bac[++tot] = (angle) {a,b};
else if (a < )
{
bac[++tot] = (angle) {a+*pi,*pi};
bac[++tot] = (angle) {,b};
}
else
{
bac[++tot] = (angle) {a,*pi};
bac[++tot] = (angle) {,b-*pi};
}
}
}
if (j != n+) continue;
sort(bac+,bac+tot+);
for (int j = ;j <= tot;++j)
{
if (bac[j].a1 > now)
{
rest += bac[j].a1 - now;
now = bac[j].a2;
}
else now = max(now,bac[j].a2);
}
rest += *pi - now;
ans += rest/(*pi) * cir[i].C();
}
} int main()
{
freopen("1043.in","r",stdin);
freopen("1043.out","w",stdout);
scanf("%d",&n);
for (int i = ;i <= n;++i) cir[i].read();
work();
printf("%.3lf",ans);
fclose(stdin); fclose(stdout);
return ;
}
BZOJ 1043 下落的圆盘的更多相关文章
- [bzoj] 1043 下落的圆盘 || 圆上的“线段覆盖”
原题 n个圆盘,求下落后能看到的总周长. 红色即为所求 借鉴于黄学长的博客 对于每下落的一个圆盘,处理他后面的圆盘会挡住哪些区域,然后把一整个圆(2\(/pi\))当做一整个区间,每个被覆盖的部分都可 ...
- bzoj 1043 下落的圆盘 —— 求圆心角、圆周长
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1043 求出每个圆没被覆盖的长度即可: 特判包含和相离的情况,注意判包含时 i 包含 j 和 ...
- bzoj1043[HAOI2008]下落的圆盘 计算几何
1043: [HAOI2008]下落的圆盘 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1598 Solved: 676[Submit][Stat ...
- 【bzoj1043】下落的圆盘
[bzoj1043]下落的圆盘 题意 有n个圆盘从天而降,后面落下的可以盖住前面的.求最后形成的封闭区域的周长.看下面这副图, 所有的红色线条的总长度即为所求. \(1\leq n\leq 1000\ ...
- 【BZOJ1043】下落的圆盘 [计算几何]
下落的圆盘 Time Limit: 10 Sec Memory Limit: 162 MB[Submit][Status][Discuss] Description 有n个圆盘从天而降,后面落下的可 ...
- 【BZOJ1043】[HAOI2008]下落的圆盘 几何
[BZOJ1043][HAOI2008]下落的圆盘 Description 有n个圆盘从天而降,后面落下的可以盖住前面的.求最后形成的封闭区域的周长.看下面这副图, 所有的红色线条的总长度即为所求. ...
- luogu P2510 [HAOI2008]下落的圆盘
LINK:下落的圆盘 计算几何.n个圆在平面上编号大的圆将编号小的圆覆盖求最后所有没有被覆盖的圆的边缘的总长度. 在做这道题之前有几个前置知识. 极坐标系:在平面内 由极点 极轴 和 极径组成的坐标系 ...
- 【BZOJ】1043: [HAOI2008]下落的圆盘(计算几何基础+贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=1043 唯一让我不会的就是怎么求圆的周长并QAAQ... 然后发现好神!我们可以将圆弧变成$[0, 2 ...
- BZOJ 1043 HAOI2008 下落的圆盘 计算几何
题目大意:n个圆盘依次下落.求终于能看到的轮廓线面积 円盘反对! 让我们一起团结起来! 赶走円盘! 咳咳.非常神的一道题 今天去看了题解和白书才搞出来-- 首先我们倒着做 对于每一个圆盘处理出在它之后 ...
随机推荐
- ImageView 缩放
<ImageView android:id="@+id/imageview" android:layout_width="wrap_content" an ...
- PPT扁平化手册 2
- IE8下提示'console'没有定义错误
在开发的过程中因为调试的原因,在代码中增加console.info("xxxx"),而未进行删除 在IE8下測试该代码所在的页面报错,例如以下: 须要注意的是,使用console对 ...
- myeclipse6.0下载及注冊码
myeclipse6.0 下载地址.官方下载地址: http://www.myeclipseide.com/module-htmlpages-display-pid-4.html 本地快速下载地址: ...
- [Angular 2] 9. Replace ng-modle with #ref & events
Let's say you want to write a simple data bing app. when you type in a text box, somewhere in the ap ...
- tcmalloc资料
1. 确定dylib在max os是可以成功的. http://lists.apple.com/archives/perfoptimization-dev/2008/Dec/msg00002.html ...
- codevs1024一塔湖图(丧心病狂的建图)
/* 丧心病狂的最短路 关键是建图 根据题目中给的路 拆出节点来 建图 (i,j) -->(j-1)*n+i 然后根据障碍 把死路 湖覆盖的dis改变成极大值 然后Floyd 然后 然后就没有然 ...
- 使用Convert 类和Parse方法将字符串转换为数值类型
//用Parse方法将字符串转换为数值类型; long num=Int64.Parse(args[2]) //用别名为Int64c#类型long; long num=long.Parse(args[2 ...
- android 蓝牙4.0 开发介绍
最近一直在研究一个蓝牙功能 由于本人是菜鸟 学起来比较忙 一直搞了好久才弄懂 , 网上对蓝牙4.0也就是几个个dome 抄来抄去,全是英文注解 , 对英语不好的朋友来说 真是硬伤 , 一些没必要的描 ...
- hibernate4.3.8整合struts2过程中遇到的问题
1.遇到的异常: Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to ...