一道树形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. SpringMVC源码情操陶冶-DispatcherServlet类简析(一)

    阅读源码有利于陶冶情操,此文承接前文SpringMVC源码情操陶冶-DispatcherServlet父类简析 注意:springmvc初始化其他内容,其对应的配置文件已被加载至beanFactory ...

  2. Linux下查看CPU、内存和硬盘信息命令

    一.查看cpu信息 cat /proc/cpuinfo 相同physical id 的记录是属于同一个CPU的,对应于多核的信息. 二.查看内存的信息 cat /proc/meminfo 三.查看硬盘 ...

  3. BZOJ 3505: [Cqoi2014]数三角形 [组合计数]

    3505: [Cqoi2014]数三角形 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个. 注意三角形的三点不能共线. 1<=m,n<=1000 $n++ m++$ $ans ...

  4. nginx隐藏版本号

    在实际运用nginx中我们最好将我们的版本号直接隐藏,因为有些版本号的nginx被爆出了漏洞,所以我们为了安全起见,最好将我们的版本号隐藏. 1.对于未安装的nginx我们使用源码编译安装才可以将版本 ...

  5. 让js调试更简单—console

    一.显示信息的命令 console.log 用于输出普通信息 console.info 用于输出提示性信息 console.error用于输出错误信息 console.warn用于输出警示信息 最常用 ...

  6. 通过WMI获取机器信息

    PerformanceCounter的介绍就不多说了,MSDN上介绍的很详细: https://msdn.microsoft.com/zh-cn/library/system.diagnostics. ...

  7. CentOS利用Nginx+Docker部署.netcore应用

    安装docker 官方文档https://docs.docker.com/engine/installation/linux/docker-ce/centos/ [root@sn ~]# yum re ...

  8. 工作中代码笔记 -- adb命令篇

    1.抓log方法 (bat文件) mkdir D:\logcatset /p miaoshu=请描述操作:adb logcat -v threadtime > D:\logcat\%miaosh ...

  9. HTTP协议学习笔记

    一.什么是HTTP协议 HTTP协议是指计算机通信网络中两台计算机之间进行通信所必须共同遵守的规定或规则,超文本传输协议(HTTP)是一种通信协议,它允许将超文本标记语言(HTML)文档从Web服务器 ...

  10. Java 求集合的所有子集

    递归方法调用,求解集合的所有子集. package ch01; import java.util.HashSet; import java.util.Iterator; import java.uti ...