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个圆盘依次下落.求终于能看到的轮廓线面积 円盘反对! 让我们一起团结起来! 赶走円盘! 咳咳.非常神的一道题 今天去看了题解和白书才搞出来-- 首先我们倒着做 对于每一个圆盘处理出在它之后 ...
随机推荐
- (转)PHP连接数据库之PHP连接MYSQL数据库代码
PHP连接数据库之PHP连接MYSQL数据库代码 < ?php $mysql_server_name='localhost'; //改成自己的mysql数据库服务器 $mysql_usernam ...
- java数组使用技巧
参考网上文章,总结了一下java数组使用技巧,如下: package com.beijing.array; import java.nio.ByteBuffer; import java.util.A ...
- Present ViewController Modally
一.主要用途 弹出模态ViewController是IOS变成中很有用的一个技术,UIKit提供的一些专门用于模态显示的ViewController,如UIImagePickerController等 ...
- [AngularJS + Webpack] Uglifying your JavaScript
Angular requires some careful consideration when uglifying your code because of how angular's depend ...
- 通知模式实现两个textField传值及模态视图——iOS开发
通知模式实现两个textField传值及模态视图--iOS开发 利用通知模式,实现两个不同界面的textField之间的传值,在界面二输入字符,传值到前一界面的textField. 界面的切换,这里临 ...
- DECIMAL Data Type
In MySQL, DECIMAL(M,D) and NUMERIC(M,D) are the same, and both have a precision of exactly M digits. ...
- eclipse 上安装systemgui
http://wiki.eclipse.org/Linux_Tools_Project/PluginInstallHelp http://wiki.eclipse.org/Linux_Tools_Pr ...
- TraceGL监控Node.js应用或者浏览器JavaScript代码
https://github.com/traceglMPL/tracegl TraceGL能够监控Node.js应用或者浏览器JavaScript代码的运行过程和细节.可视化的用户界面也很友好
- The performance between the 'normal' operation and the 'shift' operation.
First, I gonna post my test result with some code: //test the peformance of the <normal operation ...
- TSQL Beginners Challenge 1 - Find the second highest salary for each department
很久以前准备写的系列文章,后来因为懒一直耽搁着,今天突然决定继续下去,于是有了这篇文章,很基础,但很常用.题目描述依然拷贝.简单来说就是找出个个部门薪水排名第二的人,排名相同的要一起列出来. Intr ...