HDU 5934 Bomb(tarjan/SCC缩点)题解
思路:建一个有向图,指向能引爆对象,把强连通分量缩成一点,只要点燃图中入度为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缩点)题解的更多相关文章
- HDU 5934 Bomb 【图论缩点】(2016年中国大学生程序设计竞赛(杭州))
		Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ... 
- HDU 5934 Bomb(炸弹)
		p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ... 
- HDU 3072--Intelligence System【SCC缩点新构图 && 求连通全部SCC的最小费用】
		Intelligence System Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ... 
- 【(最小权点基)tarjan强连通分量缩点+tarjan模板】HDU 5934 Bomb
		[AC] #include<bits/stdc++.h> using namespace std; typedef long long ll; int n; ; ; const int i ... 
- Bomb HDU - 5934 (Tarjan)
		#include<map> #include<set> #include<ctime> #include<cmath> #include<stac ... 
- HDU 5934  (强连同分量+缩点)
		题意: 给出n个炸弹的信息 :坐标x , 坐标y , 爆炸半径 , 成本: 如果一个炸弹被引爆那这个范围的都爆炸 , 问最小的成本是多少? 题意:首先先来个n^2 暴力出某个炸弹爆炸波及的其他炸弹,用 ... 
- 【模板】Tarjan scc缩点
		代码如下 #include <bits/stdc++.h> using namespace std; const int maxv=1e4+10; const int maxe=1e5+1 ... 
- hdu 5934 Bomb
		Bomb Problem Description There are N bombs needing exploding.Each bomb has three attributes: explodi ... 
- 洛谷P2341 [HAOI2006]受欢迎的牛 (Tarjan,SCC缩点)
		P2341 [HAOI2006]受欢迎的牛|[模板]强连通分量 https://www.luogu.org/problem/P2341 题目描述 每头奶牛都梦想成为牛棚里的明星.被所有奶牛喜欢的奶牛就 ... 
随机推荐
- HFS的远程命令执行漏洞(RCE)
			一.HFS漏洞 1.影响版本 : 2.3c以前的2.3x版本 2.HFS: HFS是HTTP File Server,国外的一款HTTP 文件服务器软件,简单易上手. 3.漏洞描述: HTTP Fil ... 
- Java初学者笔记二:关于类的常见知识点汇总
			一.Java的类: Java的类是Java的基本概念了,基本的定义语法我就不提了,自己也不会忘了的,下面分成几个模块介绍: 1.Java的类定义时候的修饰符 2.Java的类的继承与派生 二.Java ... 
- PHP一句话木马小总结与SQL语句写一句话木马
			一.基础类的一句话--功能仅限于验证漏洞了,实际中太容易被查出出来: <?php @eval($_GET["code"])?> <?php @system($_P ... 
- Fluent Nhibernate Mapping for Sql Views
			Views are mapped the same way tables are mapped except that you should put Readonly() in the mapping ... 
- 【BZOJ3312】[Usaco2013 Nov]No Change 状压DP+二分
			[BZOJ3312][Usaco2013 Nov]No Change Description Farmer John is at the market to purchase supplies for ... 
- JS判断当前是否是IE浏览器,并返回时IE几?
			原文参考: https://www.cnblogs.com/liuyanxia/p/5855760.html 具体代码示例: 这里返回的是:如果不是IE浏览器返回 -1 ,返回 7/8/9/10/11 ... 
- ajax初级知识(转载)
			1.什么是ajax? Ajax 是 Asynchronous JavaScript and XML(以及 DHTML 等)的缩写. 2.ajax需要什么基础? HTML 用于建立 Web 表单并确定应 ... 
- [Gradle] 获取 gradle 命令行参数
			project.gradle.startParameter 参考 StartParameter | Gradle API 4.9 
- ORA-39006、ORA-39065、ORA-01403、ORA-39097错误解决办法
			今天有同事找说是expdp到出数据时报错: 处理方法:sys用户下执行如下语句重新生成DATAPUMP API用到的视图问题就解决了. SQL> @?/rdbms/admin/catmeta.s ... 
- MTA---smtp(25,postfix,sendmail),Pop3(110,Devocot),  MUA(foxmail) IMAP(server,client rsync)
			利用telnet进行SMTP的验证 =========先计算BASE64编码的用户名密码,认证登录需要用到=========== [crazywill@localhost crazywill]$ pe ... 
