Codeforces Round #418 (Div. 2) D. An overnight dance in discotheque 贪心
来源:互联网 发布:香港广华街枪店淘宝 编辑:程序博客网 时间:2024/06/07 10:53
题目链接: An overnight dance in discotheque
题目大意
n个圆, 他们相互之间相切相离包含, 但不会相交一幅图的总面积等于图中阴影面积
就是被包含偶数次的圆内为阴影, 被包含奇数次的圆为空白
求将一个这幅图分成两幅, 如上面两张图, 问最大阴影面积是多少
思路
最优方法: 把所有没有被包含过的圆放在第一幅图, 其他圆放在第二幅图
可以将第二幅图任何圆移到第一幅图上, 你会发现无论哪种情况, 总面积都变小或不变(相对于最优方法)
代码
#include <bits/stdc++.h>using namespace std;const int MAXN = 2000;const double pi = acos(-1.0);struct P{ double x, y, r; int times; bool operator<(const P & b) const{ return (x-b.x)*(x-b.x)+(y-b.y)*(y-b.y) < (r+b.r)*(r+b.r) && r < b.r; }//a<b a被b包含}p[MAXN];int main(){ int n; cin >> n; for(int i=0; i<n; ++i) p[i].times = 0, cin >> p[i].x >> p[i].y >> p[i].r; for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) if(i!=j && p[i]<p[j]) p[i].times++; double ans = 0; for(int i=0; i<n; ++i) if(p[i].times == 0 || p[i].times%2 == 1) ans += p[i].r*p[i].r*pi; else ans -= p[i].r*p[i].r*pi; printf("%.10f\n", ans); return 0;}
阅读全文
0 0
- Codeforces Round #418 (Div. 2) D. An overnight dance in discotheque(思维 贪心)
- Codeforces Round #418 (Div. 2) D. An overnight dance in discotheque 贪心
- Codeforces Round #418 (Div. 2) D. An overnight dance in discotheque
- codeforces 814D An overnight dance in discotheque(贪心)
- Codeforces 814D-An overnight dance in discotheque 贪心
- Codeforces-814D An overnight dance in discotheque(贪心)
- codeforces D. An overnight dance in discotheque
- coderforces 814 D. An overnight dance in discotheque(贪心)
- codeforces 814D An overnight dance in discotheque
- codeforces 814D An overnight dance in discotheque(思维)
- Codeforces 814D An overnight dance in discotheque DP(树形)
- Codeforces 814D-An overnight dance in discotheque
- Codeforces 814D An overnight dance in discotheque【思维】
- codeforces 814 D An overnight dance in discotheque
- [Codeforces 814D] An overnight dance in discotheque 树形dp,贪心
- D. An overnight dance in discotheque
- CF#418 Div2 D. An overnight dance in discotheque
- 贪心——Codeforces814D An overnight dance in discotheque
- java web中的会话技术
- Hibernate的二级缓存问题?
- 互斥锁与自旋锁
- 机器学习之numpy和matplotlib学习(二)
- 单片机时钟程序(2)control.c
- Codeforces Round #418 (Div. 2) D. An overnight dance in discotheque 贪心
- Python 刷题日记:LeetCode 204: Count Primes
- C++ linux获取系统时间
- 异常:Unable to execute dex: method ID not in [0, 0xffff]: 65536
- c与c++
- 一些MySQL语句
- Python:操作dict时避免出现KeyError的几种方法
- log4j2配置固定内容(IP等)
- JavaScript停止冒泡和阻止浏览器默认行为