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 ...
随机推荐
- [PY3]——内置数据结构(4)——字符串格式化(format)
字符串格式化是拼接字符串的一种手段 join和+拼接字符串的方法,难以控制格式 printf style 字符串格式化 这种方法是从c语言继承过来的 # 待格式化的字符串:一个字符串存在占位符 In ...
- .Net高阶异常处理第二篇~~ dump进阶之MiniDumpWriter
dump文件相信有些朋友已经很熟悉了,dump文件的作用在于保存进程运行时的堆栈信息,方便日后排查软件故障,提升软件质量.关于dump分析工具windbg.adplus的文章更多了,如果您还不知道怎么 ...
- 06.密封类 sealed
sealed 修饰 密封类是不能被继承的. 密封类是可以去继承别的类. namespace _07.密封类 { class Program { static void Main(string[] ...
- SSH框架整合中Hibernate实现Dao层常用结构
一.疑惑 一直以来,我在使用SSH框架的时候经常会发现后者有疑虑到底使用hibernate的那种方法或者如何配置hibernate来操作数据库,经过 一段时间的学习下面我来总结一下,常用的dao层配置 ...
- Oracle OCI操作UDT相关学习
1.Oracle数据类型 Oracle的数据类型如下 字符串类型 char nchar varchar2 nvarchar2 数值类型 int number integer smallint 日期类型 ...
- 设计模式入门,命令模式,c++代码实现
// test06.cpp : Defines the entry point for the console application.////设计模式第5章 命令模式#include "s ...
- IoDH 实现的单例模式
饿汉式单例类不能实现延迟加载,不管将来用不用始终占据内存:懒汉式单例类线程安全控制烦琐,而且性能受影响.有种更好的单例模式叫做Initialization Demand Holder (IoDH)的技 ...
- npm属性笔记
scripts属性,运行脚本命令的npm命令行缩写,常见如下npm run devnpm run startnpm run build dependencies属性,项目运行时配置模块依赖的模块列表, ...
- UFW Essentials: Common Firewall Rules and Commands
Introduction UFW is a firewall configuration tool for iptables that is included with Ubuntu by defau ...
- 13_Redis安全
[1.设置密码] [2.绑定IP] [3.命令禁止或重命名] [4.修改默认端口]