codeforces 814D An overnight dance in discotheque
正解:贪心。
首先我们可以计算出每个圆被多少个圆覆盖。
很显然,最外面的圆是肯定要加上的。
然后第二层的圆也是要加上的。那么第三层就不可能被加上了。同理,第四层的圆又一定会被加上。
然后我们可以发现一个贪心策略,没被覆盖和被覆盖奇数次的圆加上,被覆盖偶数次的圆减去。
可以发现这样的贪心策略是最优的。
#include <bits/stdc++.h>
#define il inline
#define RG register
#define ll long long
#define N (1005) using namespace std; const double pi=acos(-1.0); double x[N],y[N],r[N],ans;
int cov[N],n; il int gi(){
RG int x=,q=; RG char ch=getchar();
while ((ch<'' || ch>'') && ch!='-') ch=getchar();
if (ch=='-') q=-,ch=getchar();
while (ch>='' && ch<='') x=x*+ch-,ch=getchar();
return q*x;
} il double dis(RG int i,RG int j){
return sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
} il int check(RG int i,RG int j){
return r[i]<r[j] && dis(i,j)<=r[j]-r[i];
} int main(){
#ifndef ONLINE_JUDGE
freopen("dance.in","r",stdin);
freopen("dance.out","w",stdout);
#endif
n=gi();
for (RG int i=;i<=n;++i) x[i]=gi(),y[i]=gi(),r[i]=gi();
for (RG int i=;i<=n;++i)
for (RG int j=;j<=n;++j){
if (i==j) continue; cov[i]+=check(i,j);
}
for (RG int i=;i<=n;++i)
if (!cov[i]) ans+=pi*r[i]*r[i];
else if (cov[i]&) ans+=pi*r[i]*r[i];
else ans-=pi*r[i]*r[i];
printf("%0.8lf\n",ans); return ;
}
codeforces 814D An overnight dance in discotheque的更多相关文章
- CodeForces 814D An overnight dance in discotheque(贪心+dfs)
The crowdedness of the discotheque would never stop our friends from having fun, but a bit more spac ...
- Codeforces Round #418 (Div. 2) D. An overnight dance in discotheque
Codeforces Round #418 (Div. 2) D. An overnight dance in discotheque 题意: 给\(n(n <= 1000)\)个圆,圆与圆之间 ...
- An overnight dance in discotheque
An overnight dance in discotheque time limit per test 2 seconds memory limit per test 256 megabytes ...
- An overnight dance in discotheque CodeForces - 814D (几何)
大意: 给定n个不相交的圆, 求将n个圆划分成两部分, 使得阴影部分面积最大. 贪心, 考虑每个连通块, 最外层大圆分成一部分, 剩余分成一部分一定最优. #include <iostream& ...
- codeforces 814 D. An overnight dance in discotheque (贪心+bfs)
题目链接:http://codeforces.com/contest/814/problem/D 题意:给出奇数个舞者,每个舞者都有中心坐标和行动半径,而且这些点组成的园要么相互包含要么没有交集求,讲 ...
- CF#418 Div2 D. An overnight dance in discotheque
一道树形dp裸体,自惭形秽没有想到 首先由于两两圆不能相交(可以相切)就决定了一个圆和外面一个圆的包含关系 又可以发现这样的树中,奇数深度的圆+S,偶数深度的圆-S 就可以用树形dp 我又写挫了= = ...
- Codeforces 814D
题意略. 思路: 由于不重合这个性质,我们可以将每一个堆叠的圆圈单独拿出来考虑,而不用去考虑其他并列在同一层的存在, 在贪心解法下,发现,被嵌套了偶数层的圆圈永远是要被减去的,而奇数层的圆圈是要加上的 ...
- codeforces round 418 div2 补题 CF 814 A-E
A An abandoned sentiment from past 水题 #include<bits/stdc++.h> using namespace std; int a[300], ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance 模拟
D. Little Artem and Dance 题目连接: http://www.codeforces.com/contest/669/problem/D Description Little A ...
随机推荐
- Mybatis-动态SQL语句
有些时候,sql语句where条件中,需要一些安全判断,例如按某一条件查询时如果传入的参数是空,此时查询出的结果很可能是空的,也许我们需要参数为空时,是查出全部的信息.使用Oracle的序列.mysq ...
- React.js 小书 Lesson21 - ref 和 React.js 中的 DOM 操作
作者:胡子大哈 原文链接:http://huziketang.com/books/react/lesson21 转载请注明出处,保留原文链接和作者信息. 在 React.js 当中你基本不需要和 DO ...
- Java如何实现form表单提交的数据自动对应实体类(源码)
原文出自:https://blog.csdn.net/seesun2012 原生Java+JQuery form表单serializeArray提交自动对应java实体,这是一个实际的例子: html ...
- CentOS7下配置FTP服务
1.参考教程: 腾讯云开发者实验室:基于 CentOS 搭建 FTP 文件服务 Linux就该这么学>:第11章 使用Vsftpd服务传输文件 (需要自己百度) 2.实验环境: VMware 1 ...
- 第1章 初识CSS3
什么是CSS3? CSS3是CSS2的升级版本,3只是版本号,它在CSS2.1的基础上增加了很多强大的新功能. 目前主流浏览器chrome.safari.firefox.opera.甚至360都已经支 ...
- jQuery实现18位身份证输入隔位添加空格及格式验证
说明:jQuery实现身份证输入添加空格,表单验证身份证输入,并且输入时前6位添加一个空格,中间8位后添加一个空格,及身份证格式验证 参考:基于jquery实现的银行卡号每隔4位自动插入空格的实现代码 ...
- Windows 64位下安装Redis教程
Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型. Key-Value数据库,并提供多种语言的API. 一.下载 地址:Download redis-latest ...
- .NET开源工作流RoadFlow-流程运行-运行时监控
流程实例参与者都可以随时查看流程实例的运行情况,如果是待办任务,则在待办事项列表的后面点查看,如果是已完成任务则可以在已办事项列表的后面点查看: 打开之后默认为列表方式显示流程的处理过程,还可以点图形 ...
- Unity创建或克隆对象 Instantiate()
//需要创建对象 GameObject prefab; //创建对象的规定位置或父物体 Transform tr; //创建出对象 Instantiate(prefab); //创建对象,并设定位置和 ...
- 通过JavaScript创建Qml对象
有两种方法可以创建,都是全局对象Qt提供的方法 一:用Qt.createComponent加载一个qml文件并创建Component 二:用Qt.createQmlObject从一个qml字符串创建C ...