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 题目描述 每头奶牛都梦想成为牛棚里的明星.被所有奶牛喜欢的奶牛就 ...
随机推荐
- LeetCode——Count Complete Tree Nodes
Description: Given a complete binary tree, count the number of nodes. In a complete binary tree ever ...
- 窗口大小改变绑定resize事件
当为窗口绑定resize事件时,大部分浏览器会在每改变一个像素就触发一次resize事件.这严重影响了网站的性能. 解决方案是:利用settimeout方法为事件发触发的方法设置延迟执行的时间. 实现 ...
- 报错 ERROR in static/js/vendor.b3f56e9e0cd56988d890.js from UglifyJs
开发vux项目在引入 // 表单验证组件-start import zh_CN from 'vee-validate/dist/locale/zh_CN' import Validator from ...
- DNS隧道通信的检测
DNS隧道通信的检测 DNS 隧道通信 DNS 隧道通信是C&C常用的通信方式,一般常用的编码方式Base64,Binary编码,NetBios编码等,Hex编码等.且请求的Type一般都是t ...
- nginx跟tp5无法加载控制器
二. 另外502 bad gateway错误,可能是有PHP中的php-fpm.conf里 “ listen fastcgi_pass /tmp/php-cgi.sock ”跟nginx的conf文 ...
- jquery操作select标签change事件
$('#update_supply_id').on('change',function(){//判断是否选取prompt属性,无返回值: if($(this).val()){ var selectTe ...
- The Rise of Database Sharding DATABASE SHARDING
w玻璃碎片.0共享 http://www.agildata.com/database-sharding/ The Rise of Database Sharding The concept of Da ...
- List的三个子类ArrayList,LinkedList,Vector区别
一:List的三个子类的特点 ArrayList: 底层数据结构是数组,查询快,增删慢. 线程不安全,效率高.Vector: 底层数据结构是数组,查询快,增删慢. 线程安全,效率低.Vector相对A ...
- [golang note] 协程基础
协程概念 √ 协程通常称为coroutine,在golang中称为goroutine. √ 协程本质上是一种用户态线程,它不需要操作系统来进行抢占式调度,在实际实现中寄存在线程之中. √ 协程系统开销 ...
- jsoup做http接口测试
本文转载张飞的博客http://www.cnblogs.com/zhangfei/p/4359408.html在此感谢博主的分享! 最早用Jsoup是有一个小的爬虫应用要写,发现Jsoup较HttpC ...