一道树形dp裸体,自惭形秽没有想到
首先由于两两圆不能相交(可以相切)就决定了一个圆和外面一个圆的包含关系
又可以发现这样的树中,奇数深度的圆+S,偶数深度的圆-S
就可以用树形dp

我又写挫了= =

#include<cmath>
#include<map>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 1e3+5;
const int INF = 0x3f3f3f3f;
const double pi = acos(-1.0);
#define MP(x, y) make_pair(x, y) int X[N], Y[N], R[N]; int ord[N];
double S[N];
struct Node{
int to, nx;
}E[N*2];
int head[N], tot;
int dep[N];
double dp[N][2][2];
int cmp(int a, int b) {
return R[a] < R[b];
}
void gmax(double &a, double b) {
if(a < b) a = b;
} void add(int fr, int to) {
E[tot].to = to; E[tot].nx = head[fr]; head[fr] = tot++;
dep[to] ++;
}
int Incir(int a, int b) {
if(R[a] <= R[b]) return 0;
double dis = sqrt(1ll*(X[a] - X[b])*(X[a] - X[b]) + 1ll*(Y[a] - Y[b])*(Y[a] - Y[b]));
if(dis + 1.0*R[b] <= 1.0*R[a]) return 1;
else return 0;
}
void dfs(int x) {
double tmp[2][2][2];
memset(tmp, 0, sizeof(tmp)); for(int i = head[x]; ~i; i = E[i].nx) {
int to = E[i].to; dfs(to);
} for(int i = head[x]; ~i; i = E[i].nx) {
int to = E[i].to;
tmp[1][0][0] += dp[to][1][0]; tmp[1][0][1] += dp[to][1][1]; tmp[1][1][0] += dp[to][0][0]; tmp[1][1][1] += dp[to][0][1];
tmp[0][0][0] += dp[to][0][1]; tmp[0][0][1] += dp[to][0][0]; tmp[0][1][0] += dp[to][1][1]; tmp[0][1][1] += dp[to][1][0];
}
for(int i = 0; i < 2; ++i) for(int j = 0; j < 2; ++j) dp[x][i][j] = max(tmp[0][i][j] +( (j^1)? S[x]:-S[x]), tmp[1][i][j] +( (i^1)?S[x]:-S[x]));
// printf("%d %.2f %.2f %.2f %.2f %.2f %.2f\n",x, dp[x][0][0], dp[x][0][1], dp[x][1][0], dp[x][1][1], tmp[1][0][0] +( (0^1)?S[x]:-S[x]), S[x]);
} int main() {
int n;
while(~scanf("%d", &n)) {
memset(dep, 0, sizeof(dep));
memset(head, -1, sizeof(head));
tot = 0; for(int i = 0; i < n; ++i) {
scanf("%d %d %d", &X[i], &Y[i], &R[i]);
ord[i] = i;
S[i] = pi*R[i]*R[i];
}
sort(ord, ord+n, cmp); // for(int i = 0; i < n; ++i) printf("%d ", ord[i]); printf("\n");
for(int i = 0; i < n; ++i) {
for(int j = i+1; j < n; ++j) {
if(Incir(ord[j], ord[i])) { add(ord[j], ord[i]); break; }
}
} double ans = 0;
for(int i = 0; i < n; ++i) {
if(!dep[i]) {
dfs(i);
ans += dp[i][0][0];
}
}
printf("%.9f\n", ans);
}
return 0;
}

CF#418 Div2 D. An overnight dance in discotheque的更多相关文章

  1. 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)\)个圆,圆与圆之间 ...

  2. An overnight dance in discotheque

    An overnight dance in discotheque time limit per test 2 seconds memory limit per test 256 megabytes ...

  3. codeforces 814D An overnight dance in discotheque

    题目链接 正解:贪心. 首先我们可以计算出每个圆被多少个圆覆盖. 很显然,最外面的圆是肯定要加上的. 然后第二层的圆也是要加上的.那么第三层就不可能被加上了.同理,第四层的圆又一定会被加上. 然后我们 ...

  4. An overnight dance in discotheque CodeForces - 814D (几何)

    大意: 给定n个不相交的圆, 求将n个圆划分成两部分, 使得阴影部分面积最大. 贪心, 考虑每个连通块, 最外层大圆分成一部分, 剩余分成一部分一定最优. #include <iostream& ...

  5. 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 ...

  6. codeforces 814 D. An overnight dance in discotheque (贪心+bfs)

    题目链接:http://codeforces.com/contest/814/problem/D 题意:给出奇数个舞者,每个舞者都有中心坐标和行动半径,而且这些点组成的园要么相互包含要么没有交集求,讲 ...

  7. codeforces round 418 div2 补题 CF 814 A-E

    A An abandoned sentiment from past 水题 #include<bits/stdc++.h> using namespace std; int a[300], ...

  8. cf 442 div2 F. Ann and Books(莫队算法)

    cf 442 div2 F. Ann and Books(莫队算法) 题意: \(给出n和k,和a_i,sum_i表示前i个数的和,有q个查询[l,r]\) 每次查询区间\([l,r]内有多少对(i, ...

  9. CF#603 Div2

    差不多半年没打cf,还是一样的菜:不过也没什么,当时是激情,现在已是兴趣了,开心就好. A Sweet Problem 思维,公式推一下过了 B PIN Codes 队友字符串取余过了,结果今天早上一 ...

随机推荐

  1. Java设计模式——装饰模式

    转载自:http://blog.csdn.net/xu__cg/article/details/53024490 抽象构件 public interface CarInterface { void m ...

  2. bzoj 4823: [Cqoi2017]老C的方块 [最小割]

    4823: [Cqoi2017]老C的方块 题意: 鬼畜方块游戏不解释... 有些特殊边,有些四个方块组成的图形,方块有代价,删掉一些方块使得没有图形,最小化代价. 比较明显的最小割,一个图形中必须删 ...

  3. SPOJ 7258 Lexicographical Substring Search [后缀自动机 DP]

    题意:给一个长度不超过90000的串S,每次询问它的所有不同子串中,字典序第K小的,询问不超过500个. 第一道自己做的1A的SAM啦啦啦 很简单,建SAM后跑kth就行了 也需要按val基数排序倒着 ...

  4. open-falcon-agent插件使用

    说明 Plugin可以看做是对agent功能的扩充.使用插件可以对采集脚本进行统一管理,方便定制修改,也可以免去在crontab中添加计划任务. 开启plugin功能 # 修改agent配置文件 &q ...

  5. Java的一些良好习惯及细节------持续更新中...

    1.在做条件判断时,不要将变量放在判断符的左边,这样做可以防止出现空指针异常,以字符串比较为例: String name = "Tom"; //这种方式不推荐,如果变量name为空 ...

  6. 调试 smallcorgi/Faster-RCNN_TF 的demo过程遇到的问题

    最近在调试faster R-CNN时,遇到了各种各样的问题.使用的算法库为https://github.com/smallcorgi/Faster-RCNN_TF 注:本文使用的是通过virtuale ...

  7. error: Autoconf version 2.67 or higher is required

    error: Autoconf version 2.67 or higher is required 今天linux下遇到这种错误,顺便记录下来. #rpm -qf /usr/bin/autoconf ...

  8. [Python Study Notes]实现对键盘控制与监控

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  9. java泛型类的继承规则

    首先看一看java泛型类的使用: /** * 一个泛型方法:使程序更加安全 * 并且能被更多的使用 * @author 丁** * * @param <T> */ class Pair&l ...

  10. 常见HTTP状态码出现原因

    302:重定向.访问当前地址,后端重新指定一个URL,浏览器跳转到新的地址. 303:对于POST请求,它表示请求已被处理,客户端可以接着使用GET方法请求Location里的URL. 304:客户端 ...