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.
  1. 现有N颗炸弹急需引爆。
  2.  
  3. 每颗炸弹有三个属性:爆炸半径ri,炸弹位置(xi, yi),还有起爆费用ci,即你需要花费ci才能引爆这个炸弹。
  4.  
  5. 如果一颗未引爆的炸弹在另一颗炸弹的爆炸半径边缘或者其中,则会被连锁引爆。
  6.  
  7. 此时你已得知所有炸弹的属性,用最小的花费引爆所有炸弹吧。

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
  1. 第一行为一个整数T,表示测试用例的数量。
  2.  
  3. 每个测试用例开头都有一个整数N,表示炸弹的数量。
  4.  
  5. 随后N行,第i行有四个整数xiyiri,与ci,表示第i个炸弹的坐标(xi,yi),爆炸半径ri与起爆费用ci
  6.  
  7. 数据范围
  8. - T
  9. - N
  10. - −^≤xi, yi, ri≤^
  11. - 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.
  1. 对于每组测试用例,输出"Case #x: y"x表示从1开始的用例编号,y为最小费用。

CN

Sample Input - 输入样例

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

Sample Output - 输出样例

  1. Case #1: 15

题解

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

代码 C++

  1. #include <cstdio>
  2. #include <algorithm>
  3. #define ll __int64
  4. #define mx 1005
  5. int n, c[mx];
  6.  
  7. struct Edge{
  8. int to, nxt;
  9. }edge[mx*mx];
  10. int head[mx], iE;
  11. void addEdge(int u, int v){
  12. edge[iE].to = v; edge[iE].nxt = head[u];
  13. head[u] = iE++;
  14. }
  15.  
  16. struct Point{
  17. ll x, y, r;
  18. }data[mx];
  19. bool cmp(int i, int j){
  20. ll oo, rr;
  21. 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);
  22. rr = data[i].r*data[i].r;
  23. return oo <= rr;
  24. }
  25.  
  26. int stack[mx], inUS[mx], iS, ID[mx], fID[mx], iF, size[mx];
  27. void Tarjan(int now){
  28. fID[now] = ++iF;
  29. stack[++iS] = now; inUS[now] = ;
  30. int u, v, i = iS, fIDold = fID[now];
  31. for (u = head[now]; ~u; u = edge[u].nxt){
  32. v = edge[u].to;
  33. ++size[ID[v]];
  34. if (inUS[v] == ) Tarjan(v);
  35. if (~inUS[v]) fID[now] = std::min(fID[v], fID[now]);
  36. }
  37. if (fID[now] == fIDold){
  38. while (iS >= i){
  39. ID[stack[iS]] = now; inUS[stack[iS]] = -;
  40. c[now] = std::min(c[stack[iS]], c[now]);
  41. --iS;
  42. }
  43. }
  44. }
  45.  
  46. void read(){
  47. scanf("%d", &n);
  48. int i, j;
  49. for (i = ; i < n; ++i){
  50. scanf("%I64d%I64d%I64d%d", &data[i].x, &data[i].y, &data[i].r, &c[i]);
  51. head[i] = -; ID[i] = i; inUS[i] = ;
  52. }
  53. iE = ;
  54. for (i = ; i < n; ++i){
  55. for (j = i + ; j < n; ++j){
  56. if (cmp(i, j)) addEdge(i, j);
  57. if (cmp(j, i)) addEdge(j, i);
  58. }
  59. }
  60.  
  61. iS = iF = ;
  62. for (i = ; i < n; ++i){
  63. if (inUS[i] == ){ Tarjan(i); size[ID[i]] = ; }
  64. }
  65. }
  66.  
  67. int sum(){
  68. int i, opt = ;
  69. for (i = ; i < n; ++i){
  70. if (size[i] == ) opt += c[ID[i]];
  71. }
  72. return opt;
  73. }
  74.  
  75. int main(){
  76. int t, it, i;
  77. for (it = scanf("%d", &t); t; --t, ++it){
  78. read();
  79. printf("Case #%d: %d\n", it, sum());
  80. }
  81. return ;
  82. }

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. jQuery 跨域访问的三种方式 No 'Access-Control-Allow-Origin' header is present on the reque

    问题: XMLHttpRequest cannot load http://v.xxx.com. No 'Access-Control-Allow-Origin' header is present ...

  2. Linux环境数据备份Python脚本

    #!/usr/bin/python#Filename:backupscript.pyimport osimport time # The files and directories to be bac ...

  3. python web前端

    概述 HTML是英文Hyper Text Mark-up Language(超文本标记语言)的缩写,他是一种制作万维网页面标准语言(标记).相当于定义统一的一套规则,大家都来遵守他,这样就可以让浏览器 ...

  4. 关于git自己所学到的东西

    1.什么是Git(傻瓜内容跟踪器)      Git是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目 Git 是 Linus Torvalds (Linus在1991年创建了 ...

  5. com.caucho.hessian.io.HessianProtocolException: is unknown code 解决方案

    问题: Cannot access Hessian remote service at [http://....../remote/syllabusService]; nested exception ...

  6. 关于mybatis的理解

    http://blog.csdn.net/jiuqiyuliang/article/details/45132493 写的不错很好!

  7. 【《zw版·Halcon与delphi系列原创教程》 zw_halcon人脸识别

    [<zw版·Halcon与delphi系列原创教程>zw_halcon人脸识别 经常有用户问,halcon人脸识别方面的问题. 可能是cv在人脸识别.车牌识别方面的投入太多了. 其实,人脸 ...

  8. iOS的数据持久化

    所谓的持久化,就是将数据保存到硬盘中,使得在应用程序或机器重启后可以继续访问之前保存的数据.在iOS开发中,有很多数据持久化的方案,接下来我将尝试着介绍一下5种方案: plist文件(属性列表) pr ...

  9. winApi

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...

  10. rdesktop共享剪贴板的问题

    使用-r clipboard:PRIMARYCLIPBOARD参数来共享剪贴板,连接到window7 但有时就不好用了,剪贴板没有同步 找到一些相关的资料 https://bugs.launchpad ...