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. (转)小心FPGA的JTAG口(上电和下电顺序)

    同志们,根据ALTERA官方FAE(现场应用工程师)的强烈建议,请注意不要随意带电插拔你的JTAG下载接口,否则会损坏FPGA芯片的JTAG口信号管脚.现象:在排除了下载线的问题后,还是不能访问FPG ...

  2. CSS深入理解之overflow

    CSS深入理解之overflow 前言 这是跟着张鑫旭重学CSS的overflow篇 基本属性 overflow有以下五个基本属性: 1.visible : 默认值,具体表现为,应用此属性后,子元素超 ...

  3. Webform 文件上传、 C#加图片水印 、 图片验证码

    文件上传:要使用控件 - FileUpload 1.如何判断是否选中文件? FileUpload.FileName - 选中文件的文件名,如果长度不大于0,那么说明没选中任何文件 js - f.val ...

  4. Dll的生成,转化为OMF格式的DLL

    extern "C" { __declspec(dllexport) int psq_add(int a, int b); } C:\Users\pansq>mkexp my ...

  5. net core 控制台中文乱码的解决方案

    net core 对控制台中文的支持需要加入下面的语句 Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

  6. MATLAB的GUI

    % 常使用的对象查看和设置函数 % .get.set函数 ) % 获得句柄值为0的对象的属性,即显示器对象属性 plot([:]); % 绘制一幅图 title('示例'); % 增加text对象 % ...

  7. Entity Framework7 入门之全功能.NET版本下使用EF7(含源码)另附数据迁移常见错误处理

    Entity Framework7 入门之全功能.NET(Console, WinForms, WPF等)使用EF7 昨天,我们介绍了EF的新特性和开发计划,如果你还不了解,请移步 Entity Fr ...

  8. linux下JsonServer启动

    1:进入到JsonServer run.sh目录下; 2:执行"export PATH=.:$PATH"; 3:执行"run.sh start"; 这样便把Js ...

  9. SSIS变量属性中EvaluateAsExpression设置的作用

    我们在做SqlServer SSIS包开发的时候,经常会用到SSIS的变量,我们可以使用和修改SSIS变量的值使得SSIS包的逻辑更灵活,如下图所示: 在定义SSIS变量的时候可以使用固定值(如上图中 ...

  10. python之haproxy配置文件操作(第三天)

    作业: 对haproxy配置文件进行操作 要求: 对haproxy配置文件中backend下的server实现增删改查的功能 一.这个程序有二个版本 1. python2.7版本见haproxy_py ...