HDU 5934 Bomb(炸弹)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

 

Problem Description - 题目描述

There are N bombs needing exploding. 
 
Each bomb has three attributes: exploding radius ri, position (xi, yi) and lighting-cost ci which means you need to pay ci cost making it explode. 
 
If a un-lighting bomb is in or on the border the exploding area of another exploding one, the un-lighting bomb also will explode. 
 
Now you know the attributes of all bombs, please use the minimum cost to explode all bombs.
现有N颗炸弹急需引爆。

每颗炸弹有三个属性:爆炸半径ri,炸弹位置(xi, yi),还有起爆费用ci,即你需要花费ci才能引爆这个炸弹。

如果一颗未引爆的炸弹在另一颗炸弹的爆炸半径边缘或者其中,则会被连锁引爆。

此时你已得知所有炸弹的属性,用最小的花费引爆所有炸弹吧。

CN

Input - 输入
First line contains an integer T, which indicates the number of test cases. 
 
Every test case begins with an integers N, which indicates the numbers of bombs. 
 
In the following N lines, the ith line contains four intergers xi, yi, ri and ci, indicating the coordinate of ith bomb is (xi,yi), exploding radius is ri and lighting-cost is ci
 
Limits
- 1≤T≤20
- 1≤N≤1000
- −108≤xi,yi,ri≤108
- 1≤ci≤104
第一行为一个整数T,表示测试用例的数量。

每个测试用例开头都有一个整数N,表示炸弹的数量。

随后N行,第i行有四个整数xi,yi,ri,与ci,表示第i个炸弹的坐标(xi,yi),爆炸半径ri与起爆费用ci。

数据范围
- ≤T≤
- ≤N≤
- −^≤xi, yi, ri≤^
- ≤ci≤^

CN

Output - 输出

For every test case, you should output 'Case #x: y', where x indicates the case number and counts from 1 and y is the minimum cost.
对于每组测试用例,输出"Case #x: y",x表示从1开始的用例编号,y为最小费用。

CN

Sample Input - 输入样例

1
5
0 0 1 5
1 1 1 6
0 1 1 7
3 0 2 10
5 0 1 4

Sample Output - 输出样例

Case #1: 15

题解

  Tarjan缩点
  先根据每个炸弹的爆炸范围和坐标构造出一个有向图,然后再进行缩点。
  入度为0的点则为需要引爆的点,将其费用相加即是结果。

代码 C++

 #include <cstdio>
#include <algorithm>
#define ll __int64
#define mx 1005
int n, c[mx]; struct Edge{
int to, nxt;
}edge[mx*mx];
int head[mx], iE;
void addEdge(int u, int v){
edge[iE].to = v; edge[iE].nxt = head[u];
head[u] = iE++;
} struct Point{
ll x, y, r;
}data[mx];
bool cmp(int i, int j){
ll oo, rr;
oo = (data[i].x - data[j].x)*(data[i].x - data[j].x) + (data[i].y - data[j].y)*(data[i].y - data[j].y);
rr = data[i].r*data[i].r;
return oo <= rr;
} int stack[mx], inUS[mx], iS, ID[mx], fID[mx], iF, size[mx];
void Tarjan(int now){
fID[now] = ++iF;
stack[++iS] = now; inUS[now] = ;
int u, v, i = iS, fIDold = fID[now];
for (u = head[now]; ~u; u = edge[u].nxt){
v = edge[u].to;
++size[ID[v]];
if (inUS[v] == ) Tarjan(v);
if (~inUS[v]) fID[now] = std::min(fID[v], fID[now]);
}
if (fID[now] == fIDold){
while (iS >= i){
ID[stack[iS]] = now; inUS[stack[iS]] = -;
c[now] = std::min(c[stack[iS]], c[now]);
--iS;
}
}
} void read(){
scanf("%d", &n);
int i, j;
for (i = ; i < n; ++i){
scanf("%I64d%I64d%I64d%d", &data[i].x, &data[i].y, &data[i].r, &c[i]);
head[i] = -; ID[i] = i; inUS[i] = ;
}
iE = ;
for (i = ; i < n; ++i){
for (j = i + ; j < n; ++j){
if (cmp(i, j)) addEdge(i, j);
if (cmp(j, i)) addEdge(j, i);
}
} iS = iF = ;
for (i = ; i < n; ++i){
if (inUS[i] == ){ Tarjan(i); size[ID[i]] = ; }
}
} int sum(){
int i, opt = ;
for (i = ; i < n; ++i){
if (size[i] == ) opt += c[ID[i]];
}
return opt;
} int main(){
int t, it, i;
for (it = scanf("%d", &t); t; --t, ++it){
read();
printf("Case #%d: %d\n", it, sum());
}
return ;
}

HDU 5934 Bomb(炸弹)的更多相关文章

  1. HDU 5934 Bomb 【图论缩点】(2016年中国大学生程序设计竞赛(杭州))

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  2. hdu 5934 Bomb

    Bomb Problem Description There are N bombs needing exploding.Each bomb has three attributes: explodi ...

  3. HDU 5934 Bomb(tarjan/SCC缩点)题解

    思路:建一个有向图,指向能引爆对象,把强连通分量缩成一点,只要点燃图中入度为0的点即可.因为入度为0没人能引爆,不为0可以由别人引爆. 思路很简单,但是早上写的一直错,改了半天了,推倒重来才过了... ...

  4. hdu 3555 Bomb 炸弹(数位DP,入门)

    题意: 给一个数字n,求从1~n中有多少个数是含有49的,比如49,149,1490等都是含49的. 思路: 2^64也顶多是十进制的20多位,那么按十进制位来分析更简单.如果能计算k位十进制数中分别 ...

  5. 【(最小权点基)tarjan强连通分量缩点+tarjan模板】HDU 5934 Bomb

    [AC] #include<bits/stdc++.h> using namespace std; typedef long long ll; int n; ; ; const int i ...

  6. 数位DP入门之hdu 3555 Bomb

    hdu 3555 Bomb 题意: 在1~N(1<=N<=2^63-1)范围内找出含有 ‘49’的数的个数: 与hdu 2089 不要62的区别:2089是找不不含 '4'和 '62'的区 ...

  7. HDU 3622 Bomb Game(2-sat)

    HDU 3622 Bomb Game 题目链接 题意:求一个最大半径,使得每一个二元组的点任选一个,能够得到全部圆两两不相交 思路:显然的二分半径,然后2-sat去判定就可以 代码: #include ...

  8. HDU 5934:Bomb(强连通缩点)

    http://acm.hdu.edu.cn/showproblem.php?pid=5934 题意:有N个炸弹,每个炸弹有一个坐标,一个爆炸范围和一个爆炸花费,如果一个炸弹的爆炸范围内有另外的炸弹,那 ...

  9. 【HDU 5934】Bomb(强连通缩点)

    Problem Description There are N bombs needing exploding. Each bomb has three attributes: exploding r ...

随机推荐

  1. java环境变量的设置

    java安装好后需要配置一下环境变量,配置方法如下: 1.在系统变量里添加两条记录: 1)变量名:JAVA_HOME,变量值为java安装路径,如:C:\Program Files\Java\jdk1 ...

  2. 常用prototype函数

    $("spcode").value --取得当前页面的值的value,可以赋值 $F('spcode')         --不能赋值 $!spcode             - ...

  3. python requests的安装与简单运用

    requests是python的一个HTTP客户端库,跟urllib,urllib2类似,那为什么要用requests而不用urllib2呢?官方文档中是这样说明的: python的标准库urllib ...

  4. SpringMVC之控制器的单例和多例管理

    版权声明:本文为博主原创文章,未经博主允许不得转载. 在使用Spring3对控制器Controller进行bean管理时,如果要对控制器是否单例进行管理. 有两种方式配置多例模式: 1.springX ...

  5. oracle学习笔记

    --Oracle查询当前版本select * from v$version;----------Oracle 查询服务器端编码----------select * from v$nls_paramet ...

  6. 用于 Linux 平台的 Java

    切换到所需的安装目录.键入:cd directory_path_name例如,要将软件安装到 /usr/java/ 目录中,请键入:cd /usr/java/ 将 .tar.gz 档案二进制文件移到当 ...

  7. 分布式入门之1:Lease机制

      引子: 分布式系统中,如何确认一个节点是否工作正常?   如果有3副本A.B.C,并通过中心结点M来管理.其中A为主副本. 未接触过分布式的直观的处理方法是在每个副本与中心节点M中维护一个心跳,期 ...

  8. Swift_UI_UIButton

    class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // 1. 自定义 ...

  9. 利用CNN进行人脸年龄预测

    很久之前做的东西了,最近做了一个人脸相似度检测,里面用到了这里的一个模型,所以抽个空把人脸年龄检测的思路总结一下. 与其他CNN分类问题类似,人脸年龄预测无非就是将人脸分为多个类别,然后训练卷积神经网 ...

  10. nginx+tomcat+二级域名静态文件分离支持mp4视频播放配置实例

    nginx+tomcat+二级域名静态文件分离支持mp4视频播放配置实例 二级域名配置 在/etc/nginx/conf.d/目录下配置二级域名同名的conf文件,路径改成对应的即可 statics. ...