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),某 ...
随机推荐
- 从一个开发的角度看负载均衡和LVS--FullNat
从一个开发的角度看负载均衡和LVS 在大规模互联网应用中,负载均衡设备是必不可少的一个节点,源于互联网应用的高并发和大流量的冲击压力,我们通常会在服务端部署多个无状态的应用服务器和若干有状态的存储服务 ...
- php介绍
PHP 简介 PHP 是服务器端脚本语言. 您应当具备的基础知识 在继续学习之前,您需要对以下知识有基本的了解: HTML CSS 如果您希望首先学习这些项目,请在我们的 首页 访问这些教程. PHP ...
- Linux基础综合练习
Linux基本操作综合练习 1.建立用户zhangsan,密码使用明文123456: 命令:useradd -p 123456 zhangsan 解释: 参数 -p 添加明文密码 useradd添加用 ...
- 证件照制作:使用PS打印一寸照片
1. 打开文件,文件-打开-选择要操作的图片: 2. 修改图片尺寸,图像-图像大小,弹出对话框后,设置 宽度:2.5cm,高度:3.5cm,分辨率:300 像素/英寸: 3. 为要打印的照片设置白边, ...
- HTTP请求类
package com.paytest.util; import java.io.BufferedReader; import java.io.IOException; import java.io. ...
- Fail2ban 阻止暴力破解
简介: Fail2ban 能够监控系统日志,匹配日志中的错误信息(使用正则表达式),执行相应的屏蔽动作(支持多种,一般为调用 iptables ),是一款很实用.强大的软件. 如:攻击者不断尝试穷举 ...
- Bootstrip 的select的数据绑定问题
这个问题浪费了我整整一个下午时间 最后终于解决了 这里来备份一下 $(function(){ var stu_no = freeUrl(); var data, subname="&quo ...
- Java核心知识点 --- 线程中如何创建锁和使用锁 Lock , 设计一个缓存系统
理论知识很枯燥,但这些都是基本功,学完可能会忘,但等用的时候,会发觉之前的学习是非常有意义的,学习线程就是这样子的. 1.如何创建锁? Lock lock = new ReentrantLock(); ...
- Linux实战教学笔记26:http协议原理
目录 第二十六节 http协议原理 第1章 Web服务基础 1.1 http服务重要基础 1.2 HTTP协议 1.3 HTTP资源 1.4 网站流量度量术语 1.5 www服务软件介绍 1.6 本章 ...
- java算法 蓝桥杯 摆花
问题描述 小明的花店新开张,为了吸引顾客,他想在花店的门口摆上一排花,共m盆.通过调查顾客的喜好,小明列出了顾客最喜欢的n种花,从1到n标号.为了在门口展出更多种花,规定第i种花不能超过ai盆,摆花时 ...