codeforces 814 D. An overnight dance in discotheque (贪心+bfs)
题目链接:http://codeforces.com/contest/814/problem/D
题意:给出奇数个舞者,每个舞者都有中心坐标和行动半径,而且这些点组成的园要么相互包含要么没有交集求,讲这些点分成两部分最大面积是多少。
面积计算方法详见题目,很好理解有图示。
题解:这题挺简单的就考虑一下包含与不包含的就行了。具体看一下代码挺好理解的,主要是题目给出的这些点组成的园要么相互包含要么没有交集求导致
这题变得很简单
#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#define PI acos(-1)
using namespace std;
const int M = 1e3 + 10;
typedef long long ll;
vector<int>vc[M];//存该点包含的点
ll x[M] , y[M] , r[M];
ll PP(ll x) {return x * x;}
ll lowbi[M];//值为0表示该点没被包括,值不为零表示该点被其他点罩着
ll n;
ll lev[M];//下标的奇偶来判断是加还是减其实只要出现奇数次就可以加或者0的时候,由于一开始为0是不可能被包含的所以不用想加上就行。
void bfs() {
queue<int>q;
for(int i = 0 ; i < n ; i++) {
if(!lowbi[i]) q.push(i);
}
memset(lev , 0 , sizeof(lev));
while(!q.empty()) {
int v = q.front();
q.pop();
int len = vc[v].size();
for(int i = 0 ; i < len ; i++) {
int u = vc[v][i];
lev[u] = lev[v] + 1;
lowbi[u]--;
if(!lowbi[u]) q.push(u);
}
}
}
int main() {
cin >> n;
for(int i = 0 ; i < n ; i++) cin >> x[i] >> y[i] >> r[i];
for(int i = 0 ; i < n ; i++) {
for(int j = 0 ; j < n ; j++) {
if(i == j) continue;
if(r[i] > r[j] && r[i] * r[i] >= PP(x[i] - x[j]) + PP(y[i] - y[j])) {
vc[i].push_back(j);
lowbi[j]++;
}
}
}
ll ans = 0;
bfs();
for(int i = 0 ; i < n ; i++) {
if(lev[i] == 0 || lev[i] % 2) cout << i << endl , ans += r[i] * r[i];
else ans -= r[i] * r[i];
}
printf("%.12lf\n" , ans * PI);
return 0;
}
codeforces 814 D. An overnight dance in discotheque (贪心+bfs)的更多相关文章
- 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 ...
- 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 spac ...
- codeforces 814D An overnight dance in discotheque
题目链接 正解:贪心. 首先我们可以计算出每个圆被多少个圆覆盖. 很显然,最外面的圆是肯定要加上的. 然后第二层的圆也是要加上的.那么第三层就不可能被加上了.同理,第四层的圆又一定会被加上. 然后我们 ...
- An overnight dance in discotheque CodeForces - 814D (几何)
大意: 给定n个不相交的圆, 求将n个圆划分成两部分, 使得阴影部分面积最大. 贪心, 考虑每个连通块, 最外层大圆分成一部分, 剩余分成一部分一定最优. #include <iostream& ...
- CF#418 Div2 D. An overnight dance in discotheque
一道树形dp裸体,自惭形秽没有想到 首先由于两两圆不能相交(可以相切)就决定了一个圆和外面一个圆的包含关系 又可以发现这样的树中,奇数深度的圆+S,偶数深度的圆-S 就可以用树形dp 我又写挫了= = ...
- codeforces 814 C. An impassioned circulation of affection 【尺取法 or DP】
//yy:因为这题多组数据,DP预处理存储状态比每次尺取快多了,但是我更喜欢这个尺取的思想. 题目链接:codeforces 814 C. An impassioned circulation of ...
- Codeforces 669D Little Artem and Dance (胡搞 + 脑洞)
题目链接: Codeforces 669D Little Artem and Dance 题目描述: 给一个从1到n的连续序列,有两种操作: 1:序列整体向后移动x个位置, 2:序列中相邻的奇偶位置互 ...
- codeforces 814 C. An impassioned circulation of affection(二分+思维)
题目链接:http://codeforces.com/contest/814/problem/C 题意:给出一串字符串然后q个询问,问替换掉将m个字符替换为字符c,能得到的最长的连续的字符c是多长 题 ...
随机推荐
- css3系列之transform详解translate
translate translate这个参数的,是transform 身上的,那么它有什么用呢? 其实他的作用很简单,就是平移,参考自己的位置来平移 translate() translateX() ...
- 补充Java面试记录
补充Java面试记录 背景:这两天面试遇到的部分问题都分散在了前面两篇文摘中,这里再做一些其他的记录,以备不时之需! 一.谈谈你对SpringBoot的理解? SpringBoot简介:SpringB ...
- 制造资源计划(Manufacturing Resource Planning,Mrp II)
制造资源计划(Manufacturing Resource Planning,Mrp II) 概括: 以物料需求计划(MRP)为核心的企业生产管理计划系统,MRP II 是以工业工 ...
- [转载]ActiveMQ实现负载均衡+高可用部署方案
转载于 http://www.open-open.com/lib/view/open1400126457817.html 一.架构和技术介绍 1.简介 ActiveMQ 是Apache出品,最流行的, ...
- mysql的引擎问题,主键和外键的创建问题,以及创建外键不成功,却创建了一个索引
mysql的引擎问题: 需要知道的三个引擎:InnoDB--是一个事务处理引擎,不支持全文检索,支持事务操作,即DML操作: Memory--是一个数据存储在内存,速度很快,功能上等同于MyIsam, ...
- centos7之Python3.74安装
安装版本:Python3.74 系统版本:centos7 系统默认安装Python2.7,保留. 安装/usr/bin/Python3 安装需要root权限. 安装Python3的准备工作: 1.安装 ...
- 当我们尝试用JavaScipt测网速
npm包地址 https://www.npmjs.com/package/network-speed-test Github地址 https://github.com/penghuwan/networ ...
- pickle 基础用法
def save_obj_to_file(path, target_obj): file = open(path,'wb') pickle.dump(target_obj) file.close() ...
- File Compression and Archiving in linux (linux 中文件的归档)
1. Compressing Files at the Shell Prompt Red Hat Enterprise Linux provides the bzip2, gzip, and zip ...
- MySQL数据库的安装和配置
MySQL数据库介绍 什么是数据库DB? DB的全称是database,即数据库的意思.数据库实际上就是一个文件集合,是一个存储数据的仓库,数据库是按照特定的格式把数据存储起来,用户可以对存储的数据进 ...