#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. STL中vector、set、list和map

  2. 在IWMS中的分页效果

    第一步,你需要在后台修改你所要显示的新闻数目: 第二步,你需要把这段代码加到你需要分页的列表里边 代码: <%=config.TopAd%><asp:Literal id=" ...

  3. Spring Boot基础:Spring Boot简介与快速搭建(1)

    1. Spring Boot简介 Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化Spring应用的创建.运行.调试.部署等. Spring Boot默认使用tomca ...

  4. python数学第二天【泰勒展开式】

    1. 泰勒展开式 推论1: 泰勒展开式的应用 推论2: 推论3:

  5. sql 用户相关命令

    查看所有用户 select distinct concat(user, '@', host,';') as userList from mysql.user; select  #查找 distinct ...

  6. QTP 自动化测试桌面程序--笔记(关闭 启动程序脚本) 、安装

    0 安装qtp .exe 文件 安装 插件文件(如delph) 1 关闭 启动程序: 将要操作的程序-存入localdatatable中 设置 迭代一次 rem SystemUtil.ClosePro ...

  7. LR 场景选项配置--笔记

    1 tools-options --设置关系到loadgenerator行为应用于一个场景中的所有的load generator 这些设置用于未来所有运行的场景并且通常只需要设置一次 2 expert ...

  8. tensorflow点滴笔记

    1.模型保存 模型保存需要使用函数 tf.train.Saver(), a)创建saver时,可以指定需要存储的tensor,如果没有指定,则全部保存. b) 创建saver时,可以指定保存的模型个数 ...

  9. MyBatis Generator报错:Cannot instantiate object of type

    [ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate ( ...

  10. Vue插件plugins的基本操作

    前面的话 本文将详细介绍Vue插件plugins的基本操作 开发插件 插件通常会为 Vue 添加全局功能.插件的范围没有限制——一般有下面几种: 1.添加全局方法或者属性,如: vue-custom- ...