题目:http://acm.hdu.edu.cn/showproblem.php?pid=5934

There are NN bombs needing exploding. 
Each bomb has three attributes: exploding radius riri, position (xi,yi)(xi,yi) and lighting-cost cici which means you need to pay cici 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.

InputFirst line contains an integer TT, which indicates the number of test cases.

Every test case begins with an integers NN, which indicates the numbers of bombs.

In the following NN lines, the ith line contains four intergers xixi, yiyi, riri and cici, indicating the coordinate of ith bomb is (xi,yi)(xi,yi), exploding radius is riri and lighting-cost is cici.

Limits 
- 1≤T≤201≤T≤20 
- 1≤N≤10001≤N≤1000 
- −108≤xi,yi,ri≤108−108≤xi,yi,ri≤108 
- 1≤ci≤1041≤ci≤104OutputFor 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.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

题意:有n个炸弹,每个炸弹放在(x, y)这个位置,它能炸的范围是以 r 为半径的圆,手动引爆这颗炸弹所需代价是c,当一个炸弹爆炸时,

在它爆炸范围内的所有炸弹都将被它引爆,让求把所有的炸弹都引爆,所需的最少代价是多少?

建立单向图,然后缩点,每个点的权值都为它所在联通块的权值的小的那个,然后找到所有入度为0的点,将他们的权值加起来就是结果;



 #include<bits/stdc++.h>
using namespace std;
#define met(a, b) memset(a, b, sizeof(a))
typedef long long LL;
const int N=;
const int INF=0x3f3f3f3f;
const double eps=1e-; struct node{
LL x,y,r;
} a[N]; int n,w[N],Min[N],dfn[N],low[N],vis[N];
int Belong[N],Blocks,Stack[N],Top,Time,ind[N];
vector<int> G[N]; void Init()
{
for(int i=; i<=n; i++) G[i].clear();
met(Min, INF); met(ind, );
met(dfn, ); met(low, );
met(Stack, ); met(vis, );
met(Belong, );
Blocks =Top=Time = ;
} void Tajarn(int u)
{
low[u] = dfn[u] = ++Time;
Stack[Top++] = u;
vis[u] = ;
int v;
for(int i=;i<G[u].size();i++)
{
v=G[u][i];
if(!dfn[v])
{
Tajarn(v);
low[u]=min(low[u],low[v]);
}
else if(vis[v]) low[u]=min(low[u],dfn[v]);
} if(low[u]==dfn[u])
{
++Blocks;
do
{
v = Stack[--Top];
Belong[v] = Blocks;
vis[v] = ;
}while(u!=v);
}
} int main()
{
int T, t = ;
scanf("%d", &T);
while(T --)
{
scanf("%d", &n);
Init();
for(int i=;i<=n;i++) scanf("%I64d%I64d%I64d%d",&a[i].x,&a[i].y,&a[i].r,&w[i]);
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
LL d = (a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y);
if(a[i].r*a[i].r>=d) G[i].push_back(j);
}
} for(int i=;i<=n;i++) if(!dfn[i]) Tajarn(i);
for(int i=;i<=n;i++)
{
for(int j=;j<G[i].size();j++)
{
int x = G[i][j];
int u = Belong[i], v = Belong[x];
if(u != v) ind[v] ++;
Min[u] = min(Min[u], w[i]);
Min[v] = min(Min[v], w[x]);
}
} int ans = ;
for(int i=;i<=Blocks;i++) if(ind[i]==) ans+=Min[i]; printf("Case #%d: %d\n", t++, ans);
}
return ;
}

2018-09-10 16:58:27

HDU5394 Bomb的更多相关文章

  1. HDU3555 Bomb[数位DP]

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

  2. Leetcode: Bomb Enemy

    Given a 2D grid, each cell is either a wall 'W', an enemy 'E' or empty '0' (the number zero), return ...

  3. HDU 5934 Bomb(炸弹)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  4. hdu 3622 Bomb Game(二分+2-SAT)

    Bomb Game Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. Bomb

    Description The counter-terrorists found a time bomb in the dust. But this time the terrorists impro ...

  6. CF 363B One Bomb(枚举)

    题目链接: 传送门 One Bomb time limit per test:1 second     memory limit per test:256 megabytes Description ...

  7. hdu3555 Bomb (记忆化搜索 数位DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  8. [HDU3555]Bomb

    [HDU3555]Bomb 试题描述 The counter-terrorists found a time bomb in the dust. But this time the terrorist ...

  9. hdu 5934 Bomb

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

随机推荐

  1. 第一篇: openJDK源码编译安装--mac版本

    1.为什么要编译JDK 想要一探JDK内部的实现机制,最便捷的路径之一就是自己编译一套JDK,通过阅读和跟踪调试JDK源码去了解Java技术体系的原理,虽然门槛高一点,但肯定比阅读各种书籍,文章,博客 ...

  2. 力扣(LeetCode)查找常用字符 个人题解

    给定仅有小写字母组成的字符串数组 A,返回列表中的每个字符串中都显示的全部字符(包括重复字符)组成的列表.例如,如果一个字符在每个字符串中出现 3 次,但不是 4 次,则需要在最终答案中包含该字符 3 ...

  3. 软件测试的原则,软件测试计划:5W1H

    1.测试应该尽早介入.        2.所有的测试都应追溯到用户需求.        3.程序员应该避免检查自己的程序.除了单元测试.因为程序员对于自己的作品,思维具有局限性.无法保证测试质量.交给 ...

  4. Redux中间件Redux-thunk的配置

    当做固定写法吧 截图里少一个括号,已代码为主 import {createStore,applyMiddleware,compose} from 'redux' import thunk from ' ...

  5. 对js中局部变量、全局变量和闭包的理解

    对js中局部变量.全局变量和闭包的理解 局部变量 对于局部变量,js给出的定义是这样的:在 JavaScript函数内部声明的变量(使用 var)是局部变量,所以只能在函数内部访问它.(该变量的作用域 ...

  6. homebrew安装和解决brew安装速度慢的问题

    homebrew安装 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/inst ...

  7. 渗透测试初学者的靶场实战 1--墨者学院SQL注入—布尔盲注

    前言 大家好,我是一个渗透测试的爱好者和初学者,从事网络安全相关工作,由于爱好网上和朋友处找了好多关于渗透的视频.工具等资料,然后自己找了一个靶场,想把自己练习的体会和过程分享出来,希望能对其他渗透爱 ...

  8. PHP通用分页类

    Page.class.php <?php/** * 分页类 * * 调用方式: * $p=new Page(总条数,显示页数,当前页码,每页显示条数,[链接]); * print_r($p-&g ...

  9. 面试官:JVM锁优化都优化了啥?

    从JDK1.6开始,JVM对锁进行了各种优化,目的就是为了在线程间更高效的共享数据和解决互斥同步的问题.从锁优化的话题开始,可以引申出很多考点面试题,比如锁优化的技术.各优化技术的细节.CAS实现原理 ...

  10. 重写系统自带tabbar出现的 代理错误