CF#418 Div2 D. An overnight dance in discotheque
一道树形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的更多相关文章
- 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 ...
- codeforces 814D An overnight dance in discotheque
题目链接 正解:贪心. 首先我们可以计算出每个圆被多少个圆覆盖. 很显然,最外面的圆是肯定要加上的. 然后第二层的圆也是要加上的.那么第三层就不可能被加上了.同理,第四层的圆又一定会被加上. 然后我们 ...
- An overnight dance in discotheque CodeForces - 814D (几何)
大意: 给定n个不相交的圆, 求将n个圆划分成两部分, 使得阴影部分面积最大. 贪心, 考虑每个连通块, 最外层大圆分成一部分, 剩余分成一部分一定最优. #include <iostream& ...
- 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 814 D. An overnight dance in discotheque (贪心+bfs)
题目链接:http://codeforces.com/contest/814/problem/D 题意:给出奇数个舞者,每个舞者都有中心坐标和行动半径,而且这些点组成的园要么相互包含要么没有交集求,讲 ...
- codeforces round 418 div2 补题 CF 814 A-E
A An abandoned sentiment from past 水题 #include<bits/stdc++.h> using namespace std; int a[300], ...
- 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, ...
- CF#603 Div2
差不多半年没打cf,还是一样的菜:不过也没什么,当时是激情,现在已是兴趣了,开心就好. A Sweet Problem 思维,公式推一下过了 B PIN Codes 队友字符串取余过了,结果今天早上一 ...
随机推荐
- Kafka Consumer
Push VS Pull An initial question we considered is whether consumers should pull data from brokers or ...
- BZOJ 2502: 清理雪道 [最小流]
2502: 清理雪道 题意:任意点出发任意次每条边至少经过一次最小花费. 下界1,裸最小流.... #include <iostream> #include <cstdio> ...
- js实现点击切换显示隐藏,点击其它位置再隐藏
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 嵌入式linux系统的构建
前期工作:a.配置好tftp服务器:在嵌入式的童年中有介绍 b.开发板可以pc,linux 三者可以互相ping通 c.配置好nfs服务器:同样在嵌入式的童年中有介绍 一.嵌入式linux内核的制作( ...
- Hadoop源码学习之HDFS(一)
Hadoop的HDFS可以分为NameNode与DataNode,NameNode存储所有DataNode中数据的元数据信息.而DataNode负责存储真正的数据(数据块)信息以及数据块的ID. Na ...
- eslint规则
碰到eslint报错, 把错误的提示拷贝在这里Ctrl + F找到复制到eslint.js里面就行了. "off"或者0,不启用这个规则 "warn"或者1,出 ...
- tpframe框架之slide模块的使用
最新版git:https://gitee.com/37duman/tpframe 下载插件 点击下载slide插件 安装插件 把下载下来的插件解压后放置在addon文件夹 登录后台,点击插件管理 点击 ...
- 0基础学python3心得体会 - python3学习笔记 - python3基础
基础预热 print()会依次打印每个字符串,遇到逗号","会输出一个空格,可以打印整数,或者计算 结果 Python提供了一个input(),,可以让用户输入字符串,并存放到一个 ...
- 一不小心把Mysql数据库的root的账号的权限给弄没啦,该怎么办
别急啊,现在只要你还能连接到Mysql,就问题不大! 首先,连接道Mysql,这里用Navicat进行讲解. 说明:root@localhost和root@127.0.0.1不是一个账号,也不是一回事 ...
- MySQL取得某一范围随机数
①直接取值 若要在i ≤ R ≤ j 这个范围得到一个随机整数R ,需要用到表达式 FLOOR(i + RAND() * (j – i + 1)). 例如, 若要在7 到 12 的范围(包括7和12) ...