思路:建一个有向图,指向能引爆对象,把强连通分量缩成一点,只要点燃图中入度为0的点即可。因为入度为0没人能引爆,不为0可以由别人引爆。

思路很简单,但是早上写的一直错,改了半天了,推倒重来才过了...

#include<cstdio>
#include<set>
#include<stack>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn = 1000+5;
const int INF = 0x3f3f3f3f;
int head[maxn],dfn[maxn],low[maxn],vis[maxn],in[maxn],scc[maxn],val[maxn];
int tot,scc_int,index;
stack<int> st;
struct Edge{
int u,v,next;
}e[maxn*maxn];
struct Node{
ll x,y;
ll r,c;
}p[maxn]; void addEdge(int u,int v){
e[tot].u = u;
e[tot].v = v;
e[tot].next = head[u];
head[u] = tot++;
} void tarjan(int u){
vis[u] = 1;
dfn[u] = low[u] = ++index;
st.push(u);
for(int i = head[u];i != -1;i = e[i].next){
int v = e[i].v;
if(!dfn[v]){
tarjan(v);
low[u] = min(low[u],low[v]);
}
else if(vis[v]){
low[u] = min(low[u],dfn[v]);
}
}
if(dfn[u] == low[u]){
scc_int++;
ll MIN = INF;
int v;
do{
v = st.top();
st.pop();
vis[v] = 0;
scc[v] = scc_int;
MIN = min(MIN,p[v].c);
}while(v != u);
val[scc_int] = MIN;
}
}
void init(){
tot = scc_int = index = 0;
while(!st.empty()) st.pop();
memset(head,-1,sizeof(head));
memset(dfn,0,sizeof(dfn));
memset(vis,0,sizeof(vis));
memset(in,0,sizeof(in));
}
int main(){
int T,n,Case = 1;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
init();
for(int i = 1;i <= n;i++)
scanf("%lld%lld%lld%lld",&p[i].x,&p[i].y,&p[i].r,&p[i].c);
for(int i = 1;i <= n;i++){
for(int j = i + 1;j <= n;j++){
ll dis = (p[i].x - p[j].x)*(p[i].x - p[j].x) + (p[i].y - p[j].y)*(p[i].y - p[j].y);
if(p[i].r*p[i].r >= dis){
addEdge(i,j);
}
if(p[j].r*p[j].r >= dis){
addEdge(j,i);
}
}
}
for(int i = 1;i <= n;i++){
if(!dfn[i])
tarjan(i);
}
for(int i = 1; i<= n;i++){
for(int j = head[i];~j;j = e[j].next){
int v = e[j].v;
if(scc[i] != scc[v]){
in[scc[v]]++;
}
}
}
ll ans = 0;
for(int i = 1;i <= scc_int;i++){
if(in[i] == 0){
ans += val[i];
}
}
printf("Case #%d: %lld\n",Case++,ans);
}
return 0;
}

HDU 5934 Bomb(tarjan/SCC缩点)题解的更多相关文章

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

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

  2. HDU 5934 Bomb(炸弹)

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

  3. HDU 3072--Intelligence System【SCC缩点新构图 &amp;&amp; 求连通全部SCC的最小费用】

    Intelligence System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

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

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

  5. Bomb HDU - 5934 (Tarjan)

    #include<map> #include<set> #include<ctime> #include<cmath> #include<stac ...

  6. HDU 5934 (强连同分量+缩点)

    题意: 给出n个炸弹的信息 :坐标x , 坐标y , 爆炸半径 , 成本: 如果一个炸弹被引爆那这个范围的都爆炸 , 问最小的成本是多少? 题意:首先先来个n^2 暴力出某个炸弹爆炸波及的其他炸弹,用 ...

  7. 【模板】Tarjan scc缩点

    代码如下 #include <bits/stdc++.h> using namespace std; const int maxv=1e4+10; const int maxe=1e5+1 ...

  8. hdu 5934 Bomb

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

  9. 洛谷P2341 [HAOI2006]受欢迎的牛 (Tarjan,SCC缩点)

    P2341 [HAOI2006]受欢迎的牛|[模板]强连通分量 https://www.luogu.org/problem/P2341 题目描述 每头奶牛都梦想成为牛棚里的明星.被所有奶牛喜欢的奶牛就 ...

随机推荐

  1. 【Android N 7】使用量统计usagestats

    Android N 7.1.1 高通 1. /data/system/usagestats/0 2. 每天使用量统计 /data/system/usagestats/0/daily 查看数值: cat ...

  2. poj3734 Blocks[矩阵优化dp or 组合数学]

    Blocks Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6578   Accepted: 3171 Descriptio ...

  3. 配置Python实战开发环境

    一.安装Python和easy_install 和pip 新版本的linux下面应该带有这些环境,没有自带的话可以查找google配置. 二.配置python运行的虚拟化环境: 好处:Python的库 ...

  4. Android 让GridView的高度为Wrap_content根据内容自适应高度

    From:http://www.jayway.com/2012/10/04/how-to-make-the-height-of-a-gridview-wrap-its-content/ 如果把Grid ...

  5. android 软键盘回车键捕获

    EditText editText2 = (EditText)findViewById(R.id.txtTest2); editText2.setOnEditorActionListener(new ...

  6. SQL中distinct的用法(转载)

    1.作用于单列 2.作用于多列 3.COUNT统计 4.distinct必须放在开头 5.其他 在表中,可能会包含重复值.这并不成问题,不过,有时您也许希望仅仅列出不同(distinct)的值.关键词 ...

  7. PAT 1040

    字符串APPAPT中包含了两个单词"PAT",其中第一个PAT是第2位(P),第4位(A),第6位(T):第二个PAT是第3位(P),第4位(A),第6位(T). 现给定字符串,问 ...

  8. Object类中常见的方法,为什么wait notify会放在Object里边

    toString():输出一个对象的地址字符串(哈希code码):可以通过重写toString方法,获取对象的属性! equals():比较的是对象的引用是否指向同一块内存地址, 重写equals() ...

  9. postman app支持浏览器上的cookie

    1.  安装postman app 注意要安装postman application(一个应用软件),而不是chrome 插件,打开下面的这个开关 2. chrom浏览器 给chrom浏览器安装pos ...

  10. (2.15)Mysql之SQL基础——开发设计最佳规范

    (2.15)Mysql之SQL基础——开发设计最佳规范 关键字:mysql三大范式,mysql sql开发规范 分析: show profile.mysqllsla.mysqldrmpslow.exp ...