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 spaciousness won't hurt, will it?
The discotheque can be seen as an infinite xy-plane, in which there are a total of n dancers. Once someone starts moving around, they will move only inside their own movement range, which is a circular area Ci described by a center (xi, yi) and a radius ri. No two ranges' borders have more than one common point, that is for every pair (i, j) (1 ≤ i < j ≤ n) either ranges Ci and Cj are disjoint, or one of them is a subset of the other. Note that it's possible that two ranges' borders share a single common point, but no two dancers have exactly the same ranges.
Tsukihi, being one of them, defines the spaciousness to be the area covered by an odd number of movement ranges of dancers who are moving. An example is shown below, with shaded regions representing the spaciousness if everyone moves at the same time.
But no one keeps moving for the whole night after all, so the whole night's time is divided into two halves — before midnight and after midnight. Every dancer moves around in one half, while sitting down with friends in the other. The spaciousness of two halves are calculated separately and their sum should, of course, be as large as possible. The following figure shows an optimal solution to the example above.
By different plans of who dances in the first half and who does in the other, different sums of spaciousness over two halves are achieved. You are to find the largest achievable value of this sum.
The first line of input contains a positive integer n (1 ≤ n ≤ 1 000) — the number of dancers.
The following n lines each describes a dancer: the i-th line among them contains three space-separated integers xi, yi and ri( - 106 ≤ xi, yi ≤ 106, 1 ≤ ri ≤ 106), describing a circular movement range centered at (xi, yi) with radius ri.
Output one decimal number — the largest achievable sum of spaciousness over two halves of the night.
The output is considered correct if it has a relative or absolute error of at most 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if .
5
2 1 6
0 4 1
2 -1 3
1 -2 1
4 -1 1
138.23007676
8
0 0 1
0 0 2
0 0 3
0 0 4
0 0 5
0 0 6
0 0 7
0 0 8
289.02652413
The first sample corresponds to the illustrations in the legend.
题意:
平面直角坐标系中有n个圆,每两个圆之间最多只有一个交点.
要求你把圆分成两份, 每一份的圆中加上被覆盖偶数次的圆的面积,减去被覆盖奇数次的圆的面积,求两份加起来最大的面积和.
----translate by 神仙gmy
题解:
首先显然这些圆的包含关系是一棵树
现在就是要求在树上选取一些点相加再减去剩下点,使这棵树的贡献最大。
然后推一波贪心思路
首先要清楚的是一个圆的面积比他所有儿子节点面积之和还要大。
所以肯定优先选取两个平面放根节点和根节点的子节点
这样子的话孙子节点无论如何都只能减掉
此时来看第四代,要么选,减掉第五代,要么不选,加上第五代,结合上面的结论,肯定选第四代比较划算。
所以以此类推,一遍dfs就能跑出正解
代码如下:
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define int long long
using namespace std; double pi=acos(-);
struct node
{
int x,y,r;
int d1,d2,d3,d4; //d1 ue d2 shita d3 hidari d4 migi
double s;
} c[]; double ans=0.0;
vector<int> g[];
int vis[]; int check(node a,node b)
{
if(a.d1<=b.d1&&a.d2>=b.d2&&a.d3>=b.d3&&a.d4<=b.d4)
{
return ;
}
return ;
} int cmp(node a,node b)
{
return a.r<b.r;
} int n; double dfs(int now,int f,int deep)
{
vis[now]=;
double tmp=0.0;
for(int i=;i<g[now].size();i++)
{
if(g[now][i]==f) continue;
tmp+=dfs(g[now][i],now,deep+);
}
if(f==) return tmp;
return tmp+((deep&)?c[now].s:-c[now].s);
} signed main()
{
scanf("%lld",&n);
for(int i=; i<=n; i++)
{
scanf("%lld%lld%lld",&c[i].x,&c[i].y,&c[i].r);
c[i].d1=c[i].y+c[i].r;
c[i].d2=c[i].y-c[i].r;
c[i].d3=c[i].x-c[i].r;
c[i].d4=c[i].x+c[i].r;
c[i].s=c[i].r*c[i].r*pi;
}
sort(c+,c+n+,cmp);
for(int i=; i<=n; i++)
{
for(int j=i+; j<=n; j++)
{
if(check(c[i],c[j]))
{
g[i].push_back(j);
g[j].push_back(i);
break;
}
}
}
for(int i=n;i>=;i--)
{
if(!vis[i])
{
ans+=dfs(i,,)+c[i].s;
}
}
printf("%.9lf\n",ans);
}
CodeForces 814D An overnight dance in discotheque(贪心+dfs)的更多相关文章
- codeforces 814D 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 ...
- An overnight dance in discotheque CodeForces - 814D (几何)
大意: 给定n个不相交的圆, 求将n个圆划分成两部分, 使得阴影部分面积最大. 贪心, 考虑每个连通块, 最外层大圆分成一部分, 剩余分成一部分一定最优. #include <iostream& ...
- codeforces 814 D. An overnight dance in discotheque (贪心+bfs)
题目链接:http://codeforces.com/contest/814/problem/D 题意:给出奇数个舞者,每个舞者都有中心坐标和行动半径,而且这些点组成的园要么相互包含要么没有交集求,讲 ...
- CF#418 Div2 D. An overnight dance in discotheque
一道树形dp裸体,自惭形秽没有想到 首先由于两两圆不能相交(可以相切)就决定了一个圆和外面一个圆的包含关系 又可以发现这样的树中,奇数深度的圆+S,偶数深度的圆-S 就可以用树形dp 我又写挫了= = ...
- Codeforces 680D Bear and Tower of Cubes 贪心 DFS
链接 Codeforces 680D Bear and Tower of Cubes 题意 求一个不超过 \(m\) 的最大体积 \(X\), 每次选一个最大的 \(x\) 使得 \(x^3\) 不超 ...
- 小黑的镇魂曲(HDU2155:贪心+dfs+奇葩解法)
题目:点这里 题目的意思跟所谓的是英雄就下100层一个意思……在T秒内能够下到地面,就可以了(还有一个板与板之间不能超过H高). 接触这题目是在昨晚的训练赛,当时拍拍地打了个贪心+dfs,果断跟我想的 ...
- 【bzoj3252】攻略 贪心+DFS序+线段树
题目描述 题目简述:树版[k取方格数] 众所周知,桂木桂马是攻略之神,开启攻略之神模式后,他可以同时攻略k部游戏. 今天他得到了一款新游戏<XX半岛>,这款游戏有n个场景(scene),某 ...
随机推荐
- Linux 之rsyslog+LogAnalyzer 日志收集系统
一.LogAnalyzer介绍 LogAnalyzer工具提供了一个易于使用,功能强大的前端,用于搜索,查看和分析网络活动数据,包括系统日志,事件日志和其他许多日志源.由于它只是将数据展示到我们用户的 ...
- Idea2016远程调试Java项目
一.在IDEA中配置远程tomcat 1.打开配置页面 选择"+" → "Tomcat Server" → "Remote" 填写名称和目标 ...
- SSD固态盘应用于Ceph集群的四种典型使用场景
在虚拟化及云计算技术大规模应用于企业数据中心的科技潮流中,存储性能无疑是企业核心应用是否虚拟化.云化的关键指标之一.传统的做法是升级存储设备,但这没解决根本问题,性能和容量不能兼顾,并且解决不好设备利 ...
- 遇到的有关js继承和原型链的一个问题
function A(var1){ this.var1 = var1; } A.prototype = { var1:1 } var b=new A(); b.var1 = 2; var c = ne ...
- 【转】Android编码规范建议18条
转自:http://www.chinaz.com/design/2015/0908/443732.shtml Android编码规范建议18条 适合手机app设计师和android 工程师阅读. 1. ...
- [转] C#-using用法详解
转载自 WanderOCN的文章 C#-using用法详解 using 关键字有两个主要用途: (一).作为指令,用于为命名空间创建别名或导入其他命名空间中定义的类型. (二).作为语句,用于定义一个 ...
- MySQL修改redo_log_size
MySQL5.5 步骤如下: 1. set global innodb_fast_shutdown = 0; 2. mysqladmin shutdown 3. 修改my.cnf innodb_log ...
- oracle对表常用的操作
最近业务需要给表添加索引,因为数据量很大时,查询效率很低:老大建议使用索引: 之前总结的时候将索引没有记录,当然啦,也怪笔者基础薄弱,不管了,慢慢进步嘛,好了进入正题吧! 首先准备工作,先建两个临时表 ...
- addClass()使用方法
含义:为元素添加指定的样式名 具体用法分为以下两种: 1.可以一次添加一个或者多个用空格隔开的样式名 例: <script> $("ul li").addClass(& ...
- 塔防游戏 Day3
1. 添加按钮动画 选择 Button->Transition 为 Animation ,然后自定义四种状态动画即可. 2. 控制升级面板的显示和隐藏 // 升级处理 // 若点击同一炮塔,并且 ...