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 题目描述 每头奶牛都梦想成为牛棚里的明星.被所有奶牛喜欢的奶牛就 ...
随机推荐
- 【Android N 7.1.1】 ActivityManagerService 获取cpu状态
void updateCpuStatsNow() { synchronized (mProcessCpuTracker) { mProcessCpuMutexFree.set(false); fina ...
- 1296: [SCOI2009]粉刷匠[多重dp]
1296: [SCOI2009]粉刷匠 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1919 Solved: 1099[Submit][Statu ...
- 设计模式之一:单例模式(Singleton Pattern)
写这个系列的文章,只为把所学的设计模式再系统的整理一遍.错误和不周到的地方欢迎大家批评.点击这里下载源代码. 什么时候使用单例模式 在程序运行时,某种类型只需要一个实例时,一般采用单例模式.为什么需要 ...
- 【BZOJ4556】[Tjoi2016&Heoi2016]字符串 后缀数组+二分+主席树+RMQ
[BZOJ4556][Tjoi2016&Heoi2016]字符串 Description 佳媛姐姐过生日的时候,她的小伙伴从某东上买了一个生日礼物.生日礼物放在一个神奇的箱子中.箱子外边写了一 ...
- HDU 1103 Flo's Restaurant(模拟+优先队列)
Flo's Restaurant Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 使用wireshark分析TLS
1.基本概念 SSL:(Secure Socket Layer,安全套接字层),位于可靠的面向连接的网络层协议和应用层协议之间的一种协议层.SSL通过互相认证.使用数字签名确保完整性.使用加密确保私密 ...
- mrbs - 初识
一.mrbs mrbs:(meeting room booking system)会议室预订系统 二.效果 三.models from django.db import models # Create ...
- Linux eventfd分析
2017-07-20 eventfd在linux中是一个较新的进程通信方式,和信号量等不同的是event不仅可以用于进程间的通信,还可以用户内核发信号给用户层的进程.eventfd在virtIO后端驱 ...
- 【Python学习 】Python实现的FTP上传和下载功能
一.背景 最近公司的一些自动化操作需要使用Python来实现FTP的上传和下载功能.因此参考网上的例子,撸了一段代码来实现了该功能,下面做个记录. 二.ftplib介绍 Python中默认安装的ftp ...
- 为什么Log.nsf中存储的日志只有最近7天的原因
是由于Domino服务器的notes.ini配置文件中有一行参数: Log = logfilename, log_option, not_used, days, size 比如:Log=log.nsf ...