#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lowbit(x) (x & (-x)) typedef unsigned long long int ull;
typedef long long int ll;
const double pi = 4.0*atan(1.0);
const int inf = 0x3f3f3f3f;
const int maxn = ;
const int maxm = ;
const int mod = ;
using namespace std; int n, m, tol, T;
int cnt, top, sz;
struct Edge {
ll x;
ll y;
ll r;
ll w;
};
struct Node {
int u;
int v;
int next;
};
Node node[maxm];
Edge edge[maxn];
int head[maxn];
int dfn[maxn];
int low[maxn];
int fath[maxn];
int sta[maxn];
bool vis[maxn];
int point[maxn];
int ind[maxn];
ll cost[maxn]; void init() {
cnt = tol= top = sz = ;
memset(ind, , sizeof ind);
memset(sta, , sizeof sta);
memset(dfn, , sizeof(dfn));
memset(low, , sizeof(low));
memset(fath, , sizeof(fath));
memset(head, -, sizeof(head));
memset(cost, inf, sizeof cost);
memset(point, , sizeof point);
memset(vis, false, sizeof(vis));
} ll calc(int i, int j) {
ll x1 = edge[i].x;
ll x2 = edge[j].x;
ll y1 = edge[i].y;
ll y2 = edge[j].y;
ll ans = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
return ans;
} void addnode(int u, int v) {
node[tol].u = u;
node[tol].v = v;
node[tol].next = head[u];
head[u] = tol++;
} void dfs(int u) {
int v;
dfn[u] = low[u] = ++cnt;
sta[sz++] = u;
vis[u] = true;
for(int i=head[u]; ~i; i=node[i].next) {
v = node[i].v;
if(!dfn[v]) {
dfs(v);
low[u] = min(low[u], low[v]);
} else if(vis[v]) {
low[u] = min(low[u], dfn[v]);
}
}
if(low[u] == dfn[u]) {
++top;
do{
v = sta[--sz];
vis[v] = false;
point[v] = top;
} while(v != u);
}
} void tarjan() {
for(int u=; u<=n; u++) {
if(!dfn[u]) dfs(u);
}
} void solve() {
for(int u=; u<=n; u++) {
for(int i=head[u]; ~i; i=node[i].next) {
int v = node[i].v;
if(point[u] != point[v]) ind[point[v]]++;
}
}
} int main() {
scanf("%d", &T);
int cas = ;
while(T--) {
init();
scanf("%d", &n);
for(int i=; i<=n; i++) scanf("%lld%lld%lld%lld", &edge[i].x, &edge[i].y, &edge[i].r, &edge[i].w);
for(int i=; i<=n; i++) {
for(int j=; j<=n; j++) {
if(i == j) continue;
ll a = edge[i].r * edge[i].r;
ll b = calc(i, j);
if(a >= b) addnode(i, j);
}
}
tarjan();
// for(int i=1; i<=n; i++) printf("%d %d\n", i, point[i]);
solve();
// for(int i=1; i<=n; i++) printf("%d %d\n", i, ind[point[i]]);
for(int i=; i<=n; i++) {
if(!ind[point[i]]) {
cost[point[i]] = min(cost[point[i]], edge[i].w);
}
}
ll ans = ;
for(int i=; i<=top; i++) {
if(!ind[i]) ans += cost[i];
}
printf("Case #%d: %lld\n", cas++, ans);
}
return ;
}

给出n个炸弹,然后炸弹有爆炸范围,当一个炸弹爆炸的时候,这个范围内的其他炸弹也会爆炸,所以我们可以把可以相互引爆的炸弹缩成一个点,然后对于缩完以后的点,如果我缩完点的点,判断他的入度,如果我的入度不为0,说明我这个点里面的小点可以通过别的炸弹引爆它,那就没必要去炸它了,如果我的入度是0的话,我就需要手动引爆,然后去找这个点里面的小的点的引爆的最小值,然后加起来就可以了

Bomb HDU - 5934 (Tarjan)的更多相关文章

  1. Equivalent Sets HDU - 3836 (Tarjan)

    题目说给出一些子集,如果A是B的子集,B是A的子集,那么A和B就是相等的,然后给出n个集合m个关系,m个关系表示u是v的子集,问你最小再添加多少个关系可以让这n个集合都是相等的 如果这n个几个都是互相 ...

  2. Bomb HDU - 3555 (数位DP)

    Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terro ...

  3. 【BZOJ4331】[JSOI2012]越狱老虎桥(Tarjan)

    [BZOJ4331][JSOI2012]越狱老虎桥(Tarjan) 题面 BZOJ 然而BZOJ是权限题QwQ 洛谷 题解 先求出所有割边,那么显然要割掉一条割边. 如果要加入一条边,那么显然是把若干 ...

  4. 【BZOJ2208】[JSOI2010]连通数(Tarjan)

    [BZOJ2208][JSOI2010]连通数(Tarjan) 题面 BZOJ 洛谷 题解 先吐槽辣鸡洛谷数据,我写了个\(O(nm)\)的都过了. #include<iostream> ...

  5. A * B Problem Plus HDU - 1402 (FFT)

    A * B Problem Plus HDU - 1402 (FFT) Calculate A * B.  InputEach line will contain two integers A and ...

  6. D - 淡黄的长裙 HDU - 4221(贪心)

    D - 淡黄的长裙 HDU - 4221(贪心) James is almost mad! Currently, he was assigned a lot of works to do, so ma ...

  7. 浅谈强连通分量(Tarjan)

    强连通分量\(\rm (Tarjan)\)             --作者:BiuBiu_Miku \(1.\)一些术语   · 无向图:指的是一张图里面所有的边都是双向的,好比两个人打电话 \(U ...

  8. hdu---(3555)Bomb(数位dp(入门))

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

  9. hdu 5055(坑)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5055 Bob and math problem Time Limit: 2000/1000 MS ( ...

随机推荐

  1. Pseudo Registers

    Pseudoregister Description @ERR Last error value; the same value returned by the GetLastError() API ...

  2. PHP优化与提升

    一.十个不错的建议 1.使用 ip2long() 和 long2ip() 函数来把 IP 地址转化成整型存储到数据库里.这种方法把存储空间降到了接近四分之一(char(15) 的 15 个字节对整形的 ...

  3. Java中的break,continue关于标签的用法(转载)

    Java的控制循环结构中是没有关键字goto的,这种做法有它的好处,它提高了程序流程控制的可读性,但是也有不好的地方,它降低了程序流程控制的灵活性,所以说,“上帝是公平的”.所以,Java为了弥补这方 ...

  4. jQuery EasyUI 选项卡面板tabs使用实例精讲

    1. 对选项卡面板区域 div 设置 class=”easyui-tabs” 2. 对选项卡面板区域添加多个 div,每个 div 就是一个选项卡(每个面板一定设置 title) 3. 设置面板 fi ...

  5. mysql 中出现:不能打开到主机的连接,在端口3306: 连接失败

    由于某种原因,在服务器部署,然后mysql就连接不上了, navicat查看数据库正常,telnet怎么都不同,总会卡一会儿说遗失主机,最后终于找到解决办法 http://www.51testing. ...

  6. python之路--动态传参,作用域,函数嵌套

    一 . 动态传参(重点)  * ,  ** * 与 ** * 在形参位置. * 表示不定参数, 接收的是位置参数 接收到的位置参数的动态传参: 都是元组 def eat(*food): # 在形参这里 ...

  7. scrapy全站爬取拉勾网及CrawSpider介绍

    一.指定模板创建爬虫文件 命令 创建成功后的模板,把http改为https 二.CrawSpider源码介绍 1.官网介绍: 这是用于抓取常规网站的最常用的蜘蛛,因为它通过定义一组规则为跟踪链接提供了 ...

  8. GIT的前世今生

    在重点介绍GIT的一些操作之前,我们首先来说一说GIT的前世今生,了解整个版本控制的变迁能够让我们知道该如何去选择这些工具,另外通过这些技术的变迁也能够让我们对现在的技术有着更加深入的理解,在正式介绍 ...

  9. 使用synchronized 实现ReentrantLock(美团面试题目)

    刚看到这个题目的时候无从下手,因为觉得synchronized和lock在加锁的方式上有很大不同,比如,看看正常情况下synchronized时如何加锁的. 方式一: public synchroni ...

  10. Learning to Rank(转)

    https://blog.csdn.net/kunlong0909/article/details/16805889 Table of Contents 1 前言 2 LTR流程 3 训练数据的获取4 ...