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 ...
随机推荐
- SQL 除去回车符 除去空格符
update table set fa=replace(fa,chr(13),'') ; --- 除去回车符 update table set fa=replace(fa,' ','') ; --- ...
- Fastreport史无前例5折,仅十天快抢!
慧都十年第一弹,与全球顶级报表控件厂商Fastreport携手同欢:仅仅十天,仅仅提供给慧都控件网,Fastreport旗下全部产品,全部5折!立即订购>> 慧都作为中国第一家与其建立合作 ...
- SQL语句表处理
1.create table:创建表,语法: create table 表格名 ( 列名 数据类型, 列名 数据类型, ...... ) 2.constrain:约束,关键词 NOT NULL. UN ...
- javaweb之jsp的属性范围
1.什么是jsp的属性范围? 所谓的属性范围就是一个属性设置之后,可以经过多少个其他页面后仍然可以保存并继续使用.jsp提供了四种属性范围,如下: 当前页,对应的jsp对象为pageContext,属 ...
- Java 线程--继承java.lang.Thread类实现线程
现实生活中的很多事情是同时进行的,Java中为了模拟这种状态,引入了线程机制.先来看线程的基本概念. 线程是指进程中的一个执行场景,也就是执行流程,进程和线程的区别: 1.每个进程是一个应用程序,都有 ...
- java设计模式之工厂模式学习
上周安排的写两篇设计模式的文章,结果一篇也没写,今天都给写了.回顾+反思.In this world he who stops ,won't get anything he wants! 工厂方法模式 ...
- Nodejs学习笔记之复制文件
前端童鞋都知道,javascript是没有权限操作磁盘文件的,server童鞋一向都很鄙视.但是nodejs可谓让咱们前端扬眉吐气啊,最近在学node,其强大的功能让人异常激动和兴奋.今天就学习了它怎 ...
- Unicode汉字转码小工具
点击按钮即可使用! 在这里粘贴或输入 转换结果:
- Linux基础之命令练习Day2-useradd(mod,del),groupadd(mod,del),chmod,chown,
作业一: 1) 新建用户natasha,uid为1000,gid为555,备注信息为“master” 2) 修改natasha用户的家目录为/Natasha 3) 查看用户信息配置文件的最后一行 4) ...
- UMTSkeeper: keep your UMTS/GPRS/GSM connection alive automatically
UMTSkeeper: keep your UMTS/GPRS/GSM connection alive automatically by Elias from Mintaka This page i ...