HDU - 5934
tarjan 视频讲解
/**
* 题目链接:https://vjudge.net/problem/HDU-5934
* 题意:给你n个炸弹,引爆每个炸弹会有一定的花费。每个炸弹给出坐标x,y,半径r,引爆花费;
* 引爆一个炸弹会把范围内的炸弹引爆,连锁反应。 现在想把所有炸弹引爆的最小花费。
*
* 解题思路:强连通缩点。根据a能够引爆b,可以在建一条a到b的单向边。如果是一个强连通(这一部分的图,
* 任意两点都可以相互到达)那么就把这个强连通分量变成一个点,值最分量的最小值。这样图就变成有向无环图了。
* 考虑到每个点的花费都是大于0的,所以引爆开始点最划算,即为入度为0的点。
*
* 前置技能 tarjan 缩点。
*/
#include <bits/stdc++.h>
using namespace std;
const int maxn=1000+10;
const int INF=2e9+1e8;
vector<int>E[maxn];
struct Point
{
int x,y,r,cost;
}boom[maxn];
bool judge(Point a,Point b)
{
if( 1ll*(a.x-b.x)*(a.x-b.x)+1ll*(a.y-b.y)*(a.y-b.y)<=1ll*a.r*a.r ) return true;
return false;
}
int dfn[maxn],low[maxn],id,vis[maxn],ans,deg[maxn];
int num[maxn],cnt,cost[maxn];//对点进行重新编号,(数组num),按照联通分量进行编号
stack<int>S;
void init()
{
id=cnt=0;
memset(deg,0,sizeof(deg));
memset(num,0,sizeof(num));
memset(vis,0,sizeof(vis));
memset(dfn,0,sizeof(dfn));
}
void tarjan(int x)
{
low[x]=dfn[x]=++id;
S.push(x);
vis[x]=1;
for(int i=0;i<(int)E[x].size();i++)
{
int to=E[x][i];
if(!dfn[to])
{
tarjan(to);
low[x]=min(low[x],low[to]);
}
else if(vis[to]) low[x]=min(low[x],dfn[to]);
}
if(low[x]==dfn[x])
{
int mincost=INF,in=0;
cnt++;
while(1)
{
int now=S.top();
S.pop();
vis[now]=0;
num[now]=cnt;
mincost=min(mincost,boom[now].cost);
if(now==x) break;
}
cost[cnt]=mincost;
}
}
int main()
{
int T,cas=1;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
init();
for(int i=1;i<=n;i++)
{
E[i].clear();
scanf("%d%d%d%d",&boom[i].x,&boom[i].y,&boom[i].r,&boom[i].cost);
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==j) continue;
if(judge(boom[i],boom[j])) E[i].push_back(j);
}
}
for(int i=1;i<=n;i++)
if(!dfn[i]) tarjan(i);
for(int i=1;i<=n;i++)
{
for(int j=0;j<(int)E[i].size();j++)
{
int to=E[i][j];
if(num[i]!=num[to]) deg[num[to]]++;
}
}
ans=0;
for(int i=1;i<=cnt;i++) if(deg[i]==0)
ans+=cost[i];
printf("Case #%d: %d\n",cas++,ans);
}
return 0;
}
HDU - 5934的更多相关文章
- HDU 5934 Bomb(炸弹)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU 5934:Bomb(强连通缩点)
http://acm.hdu.edu.cn/showproblem.php?pid=5934 题意:有N个炸弹,每个炸弹有一个坐标,一个爆炸范围和一个爆炸花费,如果一个炸弹的爆炸范围内有另外的炸弹,那 ...
- HDU 5934 Bomb 【图论缩点】(2016年中国大学生程序设计竞赛(杭州))
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- hdu 5934 Bomb
Bomb Problem Description There are N bombs needing exploding.Each bomb has three attributes: explodi ...
- HDU 5934 强联通分量
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- Bomb HDU - 5934 (Tarjan)
#include<map> #include<set> #include<ctime> #include<cmath> #include<stac ...
- HDU 5934 Bomb(tarjan/SCC缩点)题解
思路:建一个有向图,指向能引爆对象,把强连通分量缩成一点,只要点燃图中入度为0的点即可.因为入度为0没人能引爆,不为0可以由别人引爆. 思路很简单,但是早上写的一直错,改了半天了,推倒重来才过了... ...
- HDU 5934 (强连同分量+缩点)
题意: 给出n个炸弹的信息 :坐标x , 坐标y , 爆炸半径 , 成本: 如果一个炸弹被引爆那这个范围的都爆炸 , 问最小的成本是多少? 题意:首先先来个n^2 暴力出某个炸弹爆炸波及的其他炸弹,用 ...
- 【(最小权点基)tarjan强连通分量缩点+tarjan模板】HDU 5934 Bomb
[AC] #include<bits/stdc++.h> using namespace std; typedef long long ll; int n; ; ; const int i ...
随机推荐
- python pytest
之前一直用unittest ,现在学习pytest 看看那个好 1. 安装 pip install -U pytest py.test --version 2. 只需要按照下面的规则: 测试文件以te ...
- 要胀爆的Angular1.0
尝试从http请求上遏制缓存: http://blog.csdn.net/u010039979/article/details/54376856 if (!$httpProvider.defaults ...
- Linux Samba文件共享服务配置
http://blog.csdn.net/xht555/article/details/4631063
- spring配置加载2次实例问题。
WEB.XML 中SPRING 配置及重复加载问题 Posted on 2012-11-13, 15:48, by tmser, under java 周边 . 项目内存溢出,mat 查看了一下发现s ...
- PAT 1062. 最简分数(20)
一个分数一般写成两个整数相除的形式:N/M,其中M不为0.最简分数是指分子和分母没有公约数的分数表示形式. 现给定两个不相等的正分数 N1/M1 和 N2/M2,要求你按从小到大的顺序列出它们之间分母 ...
- The path "fos_user.from_email.address" cannot contain an empty value, but got null.
The path "fos_user.from_email.address" cannot contain an empty value, but got null.. 修改 pa ...
- linux基础part4
linux基础 一.系统监控命令 1.top命令: a.如图显示使用top命令查看系统的当前运行的情况.如图对top命令执行的结果做了简单的图解,下面针对每一项做详细的解释. b.第一行显示的内容依次 ...
- eclipse---个人设置
window---- preferences -----修改背景颜色 -----修改字体 ----修改窗口主题 ----设置编码 -----设置编译环境 ----设置web项目JDK编译的版本 --- ...
- Data Structure Array: Largest subarray with equal number of 0s and 1s
http://www.geeksforgeeks.org/largest-subarray-with-equal-number-of-0s-and-1s/ #include <iostream& ...
- 【leetcode刷题笔记】Valid Number
Validate if a given string is numeric. Some examples:"0" => true" 0.1 " => ...