codeforces 814 D An overnight dance in discotheque
来源:互联网 发布:python webdriver 编辑:程序博客网 时间:2024/06/07 08:29
题目地址:http://codeforces.com/contest/814/problem/D
题意:就是告诉你有n个圆(跳舞),告诉你圆心和半径,圆两两之间不会有多余一个的交点,所以两圆之间要不是相离要不是内含。有上半场和下半场之分,每个圆只能出现一次,圆不能包含另一个圆,如果一个人跳舞被覆盖奇数次,他的面积就需要被减去,被覆盖偶数次他的面积就会被加上,然后现在问你跳舞合适的最大面积是多少。
思路:贪心,奇数加上,偶数减去
#include <iostream>#include <cstring>#include <string>#include <queue>#include <vector>#include <map>#include <algorithm>#define N 1010#define LL long long #define inf 0x3f3f3f3fusing namespace std;const double PI = 3.1415926535;struct node { double x, y, r;}yuan[N];int vis[N];double cal(node x) { return x.r*x.r*PI;}bool solve(node u, node v){ return (u.x - v.x)*(u.x - v.x) + (u.y - v.y)*(u.y - v.y)<(u.r + v.r)*(u.r + v.r);}bool cmp(node a, node b) { if (a.r == b.r) { if (a.x == b.x) { return a.y < b.y; } return a.x < b.x; } return a.r > b.r;}int main() { //cin.sync_with_stdio(false); int n; double sum; while (cin >> n) { sum = 0; for (int i = 0; i < n; i++) { cin >> yuan[i].x >> yuan[i].y >> yuan[i].r; } sort(yuan, yuan + n, cmp); memset(vis, 0, sizeof(vis)); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (solve(yuan[i], yuan[j])) { vis[j]++; } } } for (int i = 0; i < n; i++) { if (!vis[i]) { sum += cal(yuan[i]); } else if (vis[i] & 1) { sum += cal(yuan[i]); } else { sum -= cal(yuan[i]); } } printf("%.10lf\n", sum); } return 0;}
阅读全文
0 0
- codeforces 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(贪心)
- Codeforces 814D-An overnight dance in discotheque 贪心
- Codeforces-814D An overnight dance in discotheque(贪心)
- D. An overnight dance in discotheque
- coderforces 814 D. An overnight dance in discotheque(贪心)
- [Codeforces 814D] An overnight dance in discotheque 树形dp,贪心
- codeforces 814D An overnight dance in discotheque(几何思维)
- CF#418 Div2 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 Round #418 (Div. 2) D. An overnight dance in discotheque 贪心
- House Robber
- 7种形式的Android Dialog使用举例
- iptables
- C#中@的用法总结
- hadoop学习4 调测错误备案
- codeforces 814 D An overnight dance in discotheque
- Binder底层原理,aidl.java文件分析
- 欧几里得算法(辗转相除法)证明过程
- PopupWindow+ReycyclerView打造优雅的下拉列表
- spring的xml配置文件读取properties文件中的属性
- 分治法——主定理(Divide and Conquer
- 真正人工智能时代
- 为什么Java中类方法不能访问实例方法
- Ubuntu16.04配置