题目: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. map的线程安全问题

    为什么HashMap是线程不安全的 总说 HashMap 是线程不安全的,不安全的,不安全的,那么到底为什么它是线程不安全的呢?要回答这个问题就要先来简单了解一下 HashMap 源码中的使用的存储结 ...

  2. 怎样在PaaS平台上搭建一个会自动关闭的会议室

    首相得解释一下,什么叫做会自动关闭的会议室.我们的会议室是存在一个会议预定系统的,一般情况下,我们需要开会的时候,需要先抢占会议室.等待要开会的时候,去会议室里边开会,如果里边有别人,我们可以告诉他们 ...

  3. QKD 一些术语的含义

    密钥率:每个信道使用的比特数. 系统开销:不能用来提取最终密钥的信号百分比. SNU:散粒噪声单元 RNG:随机数发生器 QRNG:量子随机数发生器 TRNG:真正的随机数生成器 PRNG:伪随机数发 ...

  4. Thrift总结(四)Thrift实现双向通信

    前面介绍过 Thrift 安装和使用,介绍了Thrift服务的发布和客户端调用,可以查看我之前的文章:https://www.cnblogs.com/zhangweizhong/category/10 ...

  5. Flutter 构建的 Mac 桌面应用上无法发出网络?

    在上一篇文章中我们分享了,如何开发桌面应用.在本章文章中,来解决一下为何在 Mac 中无法发出网络情况的原因. 起因 事情​起因是这样的:我总觉得写一个 Demo 不足以体现我们开发同学的能力.直到最 ...

  6. Ubuntu 16.04.4 LTS设置root用户登陆图形界面

    普通用户登陆真是太憋屈,这也不能那也不能,root用户登录就可以肆无忌惮了 本方法采用nano编辑器,ubantu版本Ubuntu 16.04.4 LTS,其他版本应该也一样,下面进入正题 1.终端登 ...

  7. gcc在x64体系中如何传递参数,linux,mac,iOS适用

    上一篇介绍了vc(windows)平台在x64体系当中,c函数的传参方式.本篇将要介绍gcc(类linux,mac)平台在x64中,c函数是如何传参的.为节约时间和篇幅,首先来定义一个有十个参数的函数 ...

  8. BloomFilter在Hudi中的应用

    Bloom Filter在Hudi中的应用 介绍 Bloom Filter可以用于检索一个元素是否在一个集合中.它的优点是空间效率和查询时间都远远超过一般的算法,主要缺点是存在一定的误判率:当其判断元 ...

  9. java运算符详解

    java运算符: 定义:用来指明对于操作数的运算方式 按照操作数数目分类: 单目运算    数目运算    三目运算 a++              a+b           (a>b) ? ...

  10. Flex修改皮肤样式

    Flex修改皮肤大致有三种方式: (以button为例) 第一种:修改外观 1.flex项目中新建mxml外观.