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.

Input

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 xiyi and ri( - 106 ≤ xi, yi ≤ 106, 1 ≤ ri ≤ 106), describing a circular movement range centered at (xi, yi) with radius ri.

Output

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 .

Examples
input

Copy
5
2 1 6
0 4 1
2 -1 3
1 -2 1
4 -1 1
output

Copy
138.23007676
input

Copy
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
output

Copy
289.02652413
Note

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)的更多相关文章

  1. codeforces 814D An overnight dance in discotheque

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

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

  3. An overnight dance in discotheque

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

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

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

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

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

  6. CF#418 Div2 D. An overnight dance in discotheque

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

  7. Codeforces 680D Bear and Tower of Cubes 贪心 DFS

    链接 Codeforces 680D Bear and Tower of Cubes 题意 求一个不超过 \(m\) 的最大体积 \(X\), 每次选一个最大的 \(x\) 使得 \(x^3\) 不超 ...

  8. 小黑的镇魂曲(HDU2155:贪心+dfs+奇葩解法)

    题目:点这里 题目的意思跟所谓的是英雄就下100层一个意思……在T秒内能够下到地面,就可以了(还有一个板与板之间不能超过H高). 接触这题目是在昨晚的训练赛,当时拍拍地打了个贪心+dfs,果断跟我想的 ...

  9. 【bzoj3252】攻略 贪心+DFS序+线段树

    题目描述 题目简述:树版[k取方格数] 众所周知,桂木桂马是攻略之神,开启攻略之神模式后,他可以同时攻略k部游戏. 今天他得到了一款新游戏<XX半岛>,这款游戏有n个场景(scene),某 ...

随机推荐

  1. supervisor+uwsgi+django遇到writing to a closed pipe/socket/fd解决

    原因: 最近开发的一个项目,由于有个更新job需要消耗的时间非常长,一度以为更新出现了错误. 经过: 于是打开debug模式测试, 异常开启,调试发现system返回了 writing to a cl ...

  2. eclipse 使用lombok 精简java bean

    前言:             lombok 提供了简单的注解的形式来帮助我们简化消除一些必须有但显得很臃肿的 java 代码.特别是相对于 POJO             lombok 的官方网址 ...

  3. 用Theano学习Deep Learning(三):卷积神经网络

    写在前面的废话: 出了托福成绩啦,本人战战兢兢考了个97!成绩好的出乎意料!喜大普奔!撒花庆祝! 傻…………寒假还要怒学一个月刷100庆祝个毛线………… 正题: 题目是CNN,但是CNN的具体原理和之 ...

  4. CentOS7.6安装稳定版Nginx

    官网地址:http://nginx.org/en/linux_packages.html#RHEL-CentOS 需先安装依赖:sudo yum install -y yum-utils 安装开始: ...

  5. K2 Blackpearl中从数据库直接删除流程实例之K2Server表

    转:http://www.cnblogs.com/dannyli/archive/2012/11/29/2794772.html /********************************** ...

  6. UNITY UI字体模糊的原因

    根本原因:像素少. 解决办法:字体的 font size将像素设置大些,然后用scale来缩放大小

  7. unity2017.1.0f3与旧的粒子系统不兼容

    在测试旧版本插件unistorm时用unity2017.1.0f3打开后其它天气效果显示正常,雨点看不到,再用unity5.52打开后,所有效果都可以看到了. 记录备忘

  8. SYN Flood 防范

    简介: SYN Flood 是 DoS( 拒绝服务攻击 )与 DDoS( 分布式拒绝服务攻击 )的方式之一,这是一种利用 TCP 协议缺陷,发送大量伪造 TCP 连接请求,从而使得服务器资源耗尽( C ...

  9. Scala开发Hadoop示例

    import org.apache.hadoop.conf.{Configuration, Configured}; import org.apache.hadoop.util.{ToolRunner ...

  10. 读书笔记 Week6 2018-4-12

    Chap 24 重构 读书笔记 一.需求的变更 单纯就科目学习中的小项目来说,目标在一开始便被明确下来,即可定义一份严谨的列表来描述功能.故在原来的编程经历中,只要上交了程序便一切都没事儿了,也没有重 ...