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个圆盘依次下落.求终于能看到的轮廓线面积 円盘反对! 让我们一起团结起来! 赶走円盘! 咳咳.非常神的一道题 今天去看了题解和白书才搞出来-- 首先我们倒着做 对于每一个圆盘处理出在它之后 ...
随机推荐
- CSS3动画变形transition
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- MySQL 基础(DDL)
SQL分类 SQL语句主要可以划分为一下3个类别 DDL:数据定义语言,定义数据段.数据库.数据表等 DML :数据操纵语句,用于添加.删除.更新和查询数据库记录 ...
- Java学习笔记六(I/O流)
1.介绍 在实际开发过程中经常会用到数据的输入/输出操作,本篇博客着重分析一下,java中经经常使用到的有关IO操作的类.而在java中能够将经常使用的流分为两个部分:字节流和字符流. 1.流的抽象基 ...
- java Map实现的cache manager
一个模仿memcached的JAVA虚拟缓存工具,可以缓存java对象 import java.io.ByteArrayInputStream; import java.io.ByteArrayOut ...
- Spire.Barcode好用的条码生在组件
由于项目的需要,今天在网上找了一下条码的组件,发现了一个简单易用的组件,使用简单,几句代码就搞定了.
- HTML5 文件域+FileReader 分段读取文件并上传到服务器(六)
说明:使用Ajax方式上传,文件不能过大,最好小于三四百兆,因为过多的连续Ajax请求会使后台崩溃,获取InputStream中数据会为空,尤其在Google浏览器测试过程中. 1.简单分段读取文件为 ...
- Difference Between XML and XAML.
XML, or Extensible Markup Language, is a subset of the more complex SGML (Standard Generalized Mark ...
- CI 笔记2,(命令规范等)
调试模式开启,$this->output->enable_profiler(TRUE); 保留字,不能和控制器重名,有3个,CI_Controller ,Default, index.这三 ...
- 介绍TableView非常不错的一篇文章
原文:http://blog.csdn.net/fanxiaochuan/article/details/11332775 介绍TableView非常不错的一篇文章: http://www.cocoa ...
- AFN的坑--NSCachedURLResponse缓存
网络正常的情况下,如果服务器宕机或者数据库出错,会造成访问服务器报错的情况,一般报错的内容是:无法连接到服务器或者其它错误.且服务器 修复后,仍然报错.经过排查,终于找出了原因所在:AFNetwork ...