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. [Cpp primer] Namespace using Declarations

    If we want to use cin in the standard library, we need to std::cin To simplify this work, we can do ...

  2. Chrome Postman及Firefox Poster使用

    Chrome浏览器跟Postman工具共用代理设置及Cookie Firefox浏览器跟Poster工具共用代理设置及Cookie   xdebug调试原理 第一次请求url通过参数XDEBUG_SE ...

  3. JavaScript知识总结--历史-html引用方式-基础概念

    一.JavaScript简介 1.ECMAScript 1995~今已经20年的历史,产生JavaScript是需要它去解决一定的问题:在浏览器端做一些数据的验证,试想当年的网络环境,如果能够在浏览器 ...

  4. sql之分段统计

    sql之分段统计 需求:获取一个县所有家庭人数在1-2人,3-4人,5-6人,6人以上的家庭数的数组 思路:通过CASE WHEN 将 CBFCYSL分组,然后统计数据条数. 语句: SELECT T ...

  5. 变体类型 Variant VARIANT

    变体类型 Variant VARIANT class RTL_DELPHIRETURN Variant: public TVarData typedef struct    tagVARIANT  V ...

  6. malloc()与calloc区别 (转)

    另外说明: 1.分配内存空间函数malloc 调用形式: (类型说明符*) malloc (size) 功能:在内存的动态存储区中分配一块长度为"size" 字节的连续区域.函数的 ...

  7. JAVA压缩 解压缩zip 并解决linux下中文乱码

    1. [代码][Java]代码   1:再压缩前,要设置linux模式, 需要使用第三方ant-1.6.5.jar  如果是文件目录,则ZipEntry zipEntry=new ZipEntry(b ...

  8. Java 单例模式详解(转)

    概念: java中单例模式是一种常见的设计模式,单例模式分三种:懒汉式单例.饿汉式单例.登记式单例三种. 单例模式有一下特点: 1.单例类只能有一个实例. 2.单例类必须自己自己创建自己的唯一实例. ...

  9. 解决Tomcat 一闪而过的问题

    启动tomcat时cmd窗口一闪而过解决方法. 问题现象: 在实际开发中一般都是eclipse+tomcat(也许还会用到tomcat的插件),我们只需要在eclipse中单击servers上的按钮就 ...

  10. jQuery——表单异步提交

    如果不做任何处理,表单提交时会刷新页面,为了改善体验,可以使用jQuery做到异步提交表单:通过$("#form").serialize()将表单元素的数据转化为字符串,然后通过$ ...