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

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

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

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

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
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 Block[N], nBlock, Stack[N], Top, Time, degree[N];
vector<int> G[N]; void Init()
{
for(int i=; i<=n; i++)
G[i].clear();
met(Min, INF);///Min[i]表示缩点之后的每个联通块的最小代价;
met(degree, );///记录缩点之后的入度;
met(dfn, );
met(low, );
met(Stack, );
met(vis, );
met(Block, );
nBlock = Top = Time = ;
} void Tajar(int u)
{
low[u] = dfn[u] = ++Time;
Stack[Top++] = u;
vis[u] = ;
int v;
for(int i=, len=G[u].size(); i<len; i++)
{
v = G[u][i];
if(!dfn[v])
{
Tajar(v);
low[u] = min(low[u], low[v]);
}
else if(vis[v])
low[u] = min(low[u], dfn[v]);
} if(low[u] == dfn[u])
{
++ nBlock;
do
{
v = Stack[--Top];
Block[v] = nBlock;
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])
Tajar(i);
} for(int i=; i<=n; i++)
{
for(int j=,len=G[i].size(); j<len; j++)
{
int x = G[i][j];
int u = Block[i], v = Block[x];
if(u != v) degree[v] ++;
Min[u] = min(Min[u], w[i]);
Min[v] = min(Min[v], w[x]);
}
} int ans = ;
for(int i=; i<=nBlock; i++)
{
if(degree[i] == )
ans += Min[i];
}
printf("Case #%d: %d\n", t++, ans);
}
return ;
}

Bomb---hdu5934(连通图 缩点)的更多相关文章

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

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

  2. HDU 4612 Warm up 连通图缩点

    题目大意:给出一个连通图,求再一个边后,剩余的最少桥数. 题目思路:首先进行缩点得到重构后的图,求出重构后树的直径(通过两次BFS求出相距最远的两点间的距离),ans=重构图边数-树的直径 //#pr ...

  3. POJ 1236 Network of Schools 连通图缩点

    题目大意:有向图连通图,第一问求至少需要多少个软件才能传输到所有学校,第二问求至少需要增加多少条路使其成为强连通图 题目思路:利用Tarjan算法经行缩点,第一问就是求缩点后入度为0的点的个数(特殊情 ...

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

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

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

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

  6. The King’s Problem HDU - 3861(连通图 缩点 匹配)

    在一个王国里面, 国王有一个新的问题. 皇城中有N个城市M条单行路,为了让他的王国更加高效,国王想要将他的王国划分成几个州,每个城市必须属于一个州.对于两个城市(u,v),必须满足以下3个条件:   ...

  7. (连通图 缩点 强联通分支)Popular Cows -- poj --2186

    http://poj.org/problem?id=2186 Description Every cow's dream is to become the most popular cow in th ...

  8. POJ2762 单向连通图(缩点+拓扑排序

    Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19552 ...

  9. Poj 3694 Network (连通图缩点+LCA+并查集)

    题目链接: Poj 3694 Network 题目描述: 给出一个无向连通图,加入一系列边指定的后,问还剩下多少个桥? 解题思路: 先求出图的双连通分支,然后缩点重新建图,加入一个指定的边后,求出这条 ...

随机推荐

  1. ural 1143. Electric Path

    1143. Electric Path Time limit: 1.0 secondMemory limit: 64 MB Background At the team competition of ...

  2. Eclipse: JPA problem: Eclipse does not recognize content of persistence.xml

    Link: http://stackoverflow.com/questions/3701901/eclipse-does-not-recognize-content-of-persistence-x ...

  3. Document 按照xml格式输出

    private void GetXMLDocument(Document doc) { OutputFormat format1 = new OutputFormat(" ", t ...

  4. 使用javamail发信过程中的一些问题及解决方法

    http://www.blogjava.net/TrampEagle/archive/2006/05/26/48326.html 今天在研究javamail发信的过程中,出现了一些小问题,现总结如下, ...

  5. NOIp 2012 #1 Vigenère 密码 Label:模拟

    题目描述 16 世纪法国外交家 Blaise de Vigenère 设计了一种多表密码加密算法――Vigenère 密 码.Vigenère 密码的加密解密算法简单易用,且破译难度比较高,曾在美国南 ...

  6. C++ string 类的 find 方法实例详解

    1.C++ 中 string 类的 find 方法列表 size_type std::basic_string::find(const basic_string &__str, size_ty ...

  7. 测试简单for循环的效率

    os : CentOS 5.2 代码:test-usecond.c #include <stdio.h> #include <sys/time.h> // for gettim ...

  8. Linux文件/目录权限设置命令:chmod

    文件/目录权限设置命令:chmod 这是Linux系统管理员最常用到的命令之一,它用于改变文件或目录的访问权限.该命令有两种用法: 用包含字母和操作符表达式的文字设定法 其语法格式为:chmod [w ...

  9. ckedit 文本编辑器

    Ckeditor是一个功能非常强大的富文本编辑器,博客园有使用此编辑器,其功能完全可以与MS的Word媲美. 用起来也非常方便.下面是本人总结的安装步骤: 第一步,从http://ckeditor.c ...

  10. passing ‘const ’ as ‘this’ argument of ‘’ discards qualifiers 错误处理

    示例程序: #include <iostream> #include <set> using   namespace std ; class   StudentT { publ ...