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

题意:有N个炸弹,每个炸弹有一个坐标,一个爆炸范围和一个爆炸花费,如果一个炸弹的爆炸范围内有另外的炸弹,那么如果该炸弹爆炸,就会引爆所有爆炸范围内的炸弹,求让所有炸弹爆炸的最小花费。

思路:重现的时候来不及做。先n^2的把每个炸弹爆炸范围内的炸弹都连一条有向边,然后再找强连通分量缩点,这样会形成多个DAG,然后对于每个DAG找一个入度为0的点,找这个入度为0的点里面耗费最小的去引爆,就可以了。

 #include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <iostream>
#include <stack>
#include <map>
#include <queue>
using namespace std;
#define N 1010
#define INF 0x7fffffff
struct node
{
int u, v, nxt;
}edge[];
struct P
{
long long x, y, r, c;
}p[N];
int belong[N], vis[N], head[N], tot, cnt, num, dfn[N], low[N], in[N], out[N];
stack<int> sta; void init() {
tot = cnt = num = ;
memset(dfn, , sizeof(dfn));
memset(belong, , sizeof(belong));
memset(vis, , sizeof(vis));
memset(head, -, sizeof(head));
memset(in, , sizeof(in));
memset(out, , sizeof(out));
while(sta.size()) sta.pop();
} void add(int u, int v) {
edge[tot].u = u; edge[tot].v = v; edge[tot].nxt = head[u]; head[u] = tot++;
} bool dis(int u, int v) {
double a = sqrt(((p[u].x - p[v].x) * (p[u].x - p[v].x) + (p[u].y - p[v].y) * (p[u].y - p[v].y)) * 1.0);
if(a <= p[u].r) return true;
return false;
} void tarjan(int u) {
vis[u] = ;
sta.push(u);
dfn[u] = low[u] = ++cnt;
for(int i = head[u]; ~i; i = edge[i].nxt) {
int v = edge[i].v;
if(!dfn[v]) {
tarjan(v);
if(low[v] < low[u]) low[u] = low[v];
} else if(vis[v]) {
if(dfn[v] < low[u]) low[u] = dfn[v];
}
}
if(dfn[u] == low[u]) {
++num;
while(true) {
int v = sta.top(); sta.pop();
belong[v] = num; vis[v] = ;
if(v == u) break;
}
}
} int main()
{
int t, cas = ;
scanf("%d", &t);
while(t--) {
int n;
scanf("%d", &n);
init();
for(int i = ; i <= n; i++) scanf("%I64d%I64d%I64d%I64d", &p[i].x, &p[i].y, &p[i].r, &p[i].c);
for(int i = ; i <= n; i++) {
for(int j = ; j <= n; j++) {
if(i == j) continue;
if(dis(i, j)) add(i, j);
}
}
for(int i = ; i <= n; i++) if(!dfn[i]) tarjan(i);
for(int u = ; u <= n; u++) {
for(int i = head[u]; ~i; i = edge[i].nxt) {
int v = edge[i].v;
if(belong[u] != belong[v]) {
out[belong[u]]++;
in[belong[v]]++;
}
}
}
long long ans = ;
for(int i = ; i <= num; i++) {
if(in[i] == ) {
int mi = INF;
for(int j = ; j <= n; j++) {
if(belong[j] == i) {
if(p[j].c < mi) mi = p[j].c;
}
}
ans += mi;
}
}
printf("Case #%d: %d\n", cas++, ans);
}
return ;
}

HDU 5934:Bomb(强连通缩点)的更多相关文章

  1. HDU 5934 Bomb(炸弹)

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

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

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

  3. 【(最小权点基)tarjan强连通分量缩点+tarjan模板】HDU 5934 Bomb

    [AC] #include<bits/stdc++.h> using namespace std; typedef long long ll; int n; ; ; const int i ...

  4. HDU 5934 Bomb(tarjan/SCC缩点)题解

    思路:建一个有向图,指向能引爆对象,把强连通分量缩成一点,只要点燃图中入度为0的点即可.因为入度为0没人能引爆,不为0可以由别人引爆. 思路很简单,但是早上写的一直错,改了半天了,推倒重来才过了... ...

  5. hdu 5934 Bomb

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

  6. HDU 3639 Hawk-and-Chicken (强连通缩点+DFS)

    <题目链接> 题目大意: 有一群孩子正在玩老鹰抓小鸡,由于想当老鹰的人不少,孩子们通过投票的方式产生,但是投票有这么一条规则:投票具有传递性,A支持B,B支持C,那么C获得2票(A.B共两 ...

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

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

  8. hdu 4635 Strongly connected 强连通缩点

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4635 题意:给你一个n个点m条边的图,问在图不是强连通图的情况下,最多可以向图中添多少条边,若图为原来 ...

  9. HDU 3639 Hawk-and-Chicken(强连通分量+缩点)

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/u013480600/article/details/32140501 HDU 3639 Hawk-a ...

  10. hdu 2767 Proving Equivalences 强连通缩点

    给出n个命题,m个推导,问最少添加多少条推导,能够使全部命题都能等价(两两都能互推) 既给出有向图,最少加多少边,使得原图变成强连通. 首先强连通缩点,对于新图,每一个点都至少要有一条出去的边和一条进 ...

随机推荐

  1. boost 1.57.0安装

    一. PC编译安装boost boost是C++的准标准库,其有两种安装方法. 1. ubuntu下,通过sudo apt-get install libboost-all-dev. 2. 通过源码包 ...

  2. selenium 基本了解

    Selenium的界面 白色:还未执行 浅青色:动作成功 深青色:判断成功 浅粉红色:判断失败,但不影响测试案例的运行 深粉红色:判断失败,且测试案例无法正常运行 Command 存在的命令 Acti ...

  3. MySQLdb模块 类操作方法

    #!/usr/bin/env python #-*- coding:utf- -*- from day5 import conf import MySQLdb class MysqlHepler(ob ...

  4. 用UIImageView作出动画效果

    #import "AppDelegate.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL ...

  5. Visual Studio Online

    删除Visual Studio Online的项目http://taslimi.me/how-to-delete-a-team-project-from-tfs-online-tfs.visualst ...

  6. eclipse 插件未安装成功定位

    以gef未安装成功为例 在eclipse根目录下: eclipse –clean –console –noExit 右击窗口标题栏,属性,勾中快速编辑模式,这样可以在命令行窗口点击右键将剪贴板上的内容 ...

  7. 数据存储之plist、偏好设置

    // 偏好设置--------------------------------- // 存储基本类型数据 NSUserDefaults *defaults = [NSUserDefaults stan ...

  8. C# 以管理员方式启动Winform,进而使用管理员控制Windows Service

    问题起因: 1,) 问题自动分析Windows服务在正常运行时,确实会存在程序及人为原因导致该服务停止.为了在应用程序使用时确保该服务正常运行,于是有了该讨论主题. 2,)一般账户(尽管是管理员组账户 ...

  9. Leetcode: Combination Sum IV && Summary: The Key to Solve DP

    Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...

  10. UVa10025-The ? 1 ? 2 ? ... ? n = k problem

    分析:因为数字之间只有加减变换,所以-k和k是一样的,都可以当成整数来考虑,只要找到最小的n满足sum=n*(n+1)/2>=k:且sum和k同奇同偶即可,做法是用二分查找,然后在就近查找 因为 ...