Bomb HDU - 5934 (Tarjan)
#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)的更多相关文章
- Equivalent Sets HDU - 3836 (Tarjan)
题目说给出一些子集,如果A是B的子集,B是A的子集,那么A和B就是相等的,然后给出n个集合m个关系,m个关系表示u是v的子集,问你最小再添加多少个关系可以让这n个集合都是相等的 如果这n个几个都是互相 ...
- Bomb HDU - 3555 (数位DP)
Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terro ...
- 【BZOJ4331】[JSOI2012]越狱老虎桥(Tarjan)
[BZOJ4331][JSOI2012]越狱老虎桥(Tarjan) 题面 BZOJ 然而BZOJ是权限题QwQ 洛谷 题解 先求出所有割边,那么显然要割掉一条割边. 如果要加入一条边,那么显然是把若干 ...
- 【BZOJ2208】[JSOI2010]连通数(Tarjan)
[BZOJ2208][JSOI2010]连通数(Tarjan) 题面 BZOJ 洛谷 题解 先吐槽辣鸡洛谷数据,我写了个\(O(nm)\)的都过了. #include<iostream> ...
- 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 ...
- D - 淡黄的长裙 HDU - 4221(贪心)
D - 淡黄的长裙 HDU - 4221(贪心) James is almost mad! Currently, he was assigned a lot of works to do, so ma ...
- 浅谈强连通分量(Tarjan)
强连通分量\(\rm (Tarjan)\) --作者:BiuBiu_Miku \(1.\)一些术语 · 无向图:指的是一张图里面所有的边都是双向的,好比两个人打电话 \(U ...
- hdu---(3555)Bomb(数位dp(入门))
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submi ...
- hdu 5055(坑)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5055 Bob and math problem Time Limit: 2000/1000 MS ( ...
随机推荐
- 同一个机器 安装多个版本Chrome浏览器的方法
1. Chrome 现在安装直接没有任何提示 就直接安装了 而且自动式 高版本覆盖低版本安装 不给你任何选择版本的机会. 2. 但是chrome 的安装是基于用户的 所以 同一个机器 使用不同的用户 ...
- 将表单数据转换为json代码分享
<body> <form action="#" method="post" id="form1"> <inpu ...
- git fetch 和git pull 的差别
1.git fetch 相当于是从远程获取最新到本地,不会自动merge,如下指令: git fetch orgin master //将远程仓库的master分支下载到本地当前branch中 git ...
- day 7-20 视图,触发器,事务
一.视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,可以将该结果集当做表来使用. 使用视图我们可以把查询过程中的 ...
- Android——MaterialDesign之一Toolbar
Toolbar 由于ActionBar设计原因只能存在活动的顶部,从而不能实现MaterialDesign的效果,现在推荐使用Toolbar,继承Actionbar,但是比起它更加的灵活. 设置主题: ...
- k8s容器的资源限制
1.k8s支持内存和cpu的限制 requests:容器运行需求,最低保障limits:限制,硬限制(资源上限) CPU: 1颗逻辑CPU(1核CPU=4个逻辑CPU) 1物理核=1000个微核(mi ...
- 使用synchronized 实现ReentrantLock(美团面试题目)
刚看到这个题目的时候无从下手,因为觉得synchronized和lock在加锁的方式上有很大不同,比如,看看正常情况下synchronized时如何加锁的. 方式一: public synchroni ...
- Python memecache
memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载,故常用来做数据库缓存.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态 ...
- solr安装配置(一)
本文使用的solr版本是solr-5.5.5. 步骤: 1.解压solr压缩包. 2.将solr-5.5.5\server\solr-webapp目录下面的文件拷贝到Tomcat的webapps目录下 ...
- TP5系统变量输出
1.超全局变量 模板中: {$Think.sever.server_name} //全部小写,输出blog.cn 控制器: $_SERVER['SERVER_NAME'] ...