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. Newtonsoft.Json[C#]

    C# Newtonsoft.Json JsonSerializerSettings配置序列化操作 https://blog.csdn.net/u011127019/article/details/72 ...

  2. yarn学习

  3. Linux内核系统调用列表

    一.进程控制: fork 创建一个新进程 clone 按指定条件创建子进程 execve 运行可执行文件 exit 中止进程 _exit 立即中止当前进程 getdtablesize 进程所能打开的最 ...

  4. Strem String Memory TStringStream

    System.SysUtils 一.TStringStream方法 Strem>String TMemoryStream to String stm: TStream; ss: TStringS ...

  5. Adjacent Bit Counts(uvalive)

    For a string of n bits x1, x2, x3,…, xn, the adjacent bit count of the string (AdjBC(x)) is given by ...

  6. python:一个轻松的递归逻辑

    #递归 age = 10 def dig(n): global age#函数dig引用全局变量age age += 2 n -= 1 if n != 1:#如果满足条件,则调用本身 dig(n) di ...

  7. linux/ubuntu 端口开放

    在ubuntu下面开放端口好像主要有两种方法,一种是ubuntu自带的防火墙,一种是iptables,这里我们主要使用iptables.本文的系统版本为ubuntu14.04和ubuntu16.04 ...

  8. 获取当前UnixTime的零点时间戳

    最近有个需求,开屏广告每天只出一次. 思路为如果出了开屏广告,则记录当前时间,下次来的时候,读取当前时间和上一次出开屏的时间. 算一下是不是在同一天即可. 我们的第一个想法是将上次开屏时间和当前时间归 ...

  9. spring注解扫描组件注册

    最近对单点系统进行微服务拆分,被各个springboot的组件注册搞得云里雾里的.(有的是通过springboot的自动配置进IOC容器的,有的是自己添加构造方法添加进IOC容器.)决定抽时间将spr ...

  10. Linux实战教学笔记40: Mha-Atlas-MySQL高可用方案实践(二)

    六,配置VIP漂移 主机名 IP地址(NAT) 漂移VIP 描述 mysql-db01 eth0:192.168.0.51 VIP:192.168.0.60 系统:CentOS6.5(6.x都可以) ...