#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. PHP的内存回收(GC)

    php官方对gc的介绍:http://php.net/manual/zh/features.gc.php

  2. 解决ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。

    解决办法:

  3. Migrate MySQL database using dump and restore

    kaorimatz/mysqldump-loader: Load a MySQL dump file using LOAD DATA INFILEhttps://github.com/kaorimat ...

  4. [转帖]FORFILES 的简单介绍。

    FORFILES https://blog.csdn.net/sandy9919/article/details/82932460 命令格式: forfiles.exe /p "D:\备份& ...

  5. ORA-28000: the account is locked解决办法

    ORA-28000: the account is locked第一步:使用PL/SQL,登录名为system,数据库名称不变,选择类型的时候把Normal修改为Sysdba;第二步:选择myjob, ...

  6. Mysql DBA 运维 MySQL数据库索引优化及数据丢失案例 MySQL备份-增量备份及数据恢复基础实战 MySQL数据库生产场景核心优化

    需要的联系我,QQ:1844912514

  7. 日期选择器date、week、time、datetime、datetime-local类型

    下面只写两个类型的代码案例,其他都大同小异 date类型: <!DOCTYPE html> <html> <head> <meta charset=" ...

  8. __new__和__init__的区别

    __new__是一个静态方法,而__init__是一个实例方法. __new__方法会返回一个创建的实例,而__init__什么都不返回. 只有在__new__返回一个cls的实例时后面的__init ...

  9. DTW的原理及matlab实现

    参考: https://www.cnblogs.com/Daringoo/p/4095508.html

  10. Hbase存储模式

    以key.value的结构存储数据;  (table,rowkey,family,colum,timestamp)构成数据的key,value存储数据