HDU 5934 强联通分量
Bomb
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1853 Accepted Submission(s): 608
Each bomb has three attributes: exploding radius ri, position (xi,yi) and lighting-cost ci which means you need to pay ci cost making it explode.
If a un-lighting bomb is in or on the border the exploding area of another exploding one, the un-lighting bomb also will explode.
Now you know the attributes of all bombs, please use the minimum cost to explode all bombs.
Every test case begins with an integers N, which indicates the numbers of bombs.
In the following N lines, the ith line contains four intergers xi, yi, ri and ci, indicating the coordinate of ith bomb is (xi,yi), exploding radius is ri and lighting-cost is ci.
Limits
- 1≤T≤20
- 1≤N≤1000
- −108≤xi,yi,ri≤108
- 1≤ci≤104
5
0 0 1 5
1 1 1 6
0 1 1 7
3 0 2 10
5 0 1 4
思路:将给出的点之间连边,对每个强联通分量去最小值即可。
代码:
```C++
#include<bits/stdc++.h>
//#include<regex>
#define db double
#include<vector>
#define ll long long
#define vec vector<ll>
#define Mt vector<vec>
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
#define MP make_pair
#define PB push_back
#define inf 0x3f3f3f3f3f3f3f3f
#define fr(i, a, b) for(int i=a;i<=b;i++)
const int N = 4e6 + ;
const int mod = 1e9 + ;
const int MOD = mod - ;
const db eps = 1e-;
const db PI = acos(-1.0);
using namespace std;
struct P {
int f, to, nxt;
} e[N]; struct PP {
int x, y, r, c;
} a[N];
int hea[];
int n, cnt, sig, tt, cont;
int deg[], sta[], col[], vis[], low[], dfn[], need[], contz[]; void add(int f, int to) {//建边
e[cont].to = to;
e[cont].f = f;
e[cont].nxt = hea[f];
hea[f] = cont++;
} void tarjan(int u) {//强联通分量
vis[u] = ;
low[u] = dfn[u] = cnt++;
sta[++tt] = u;
for (int i = hea[u]; i != -; i = e[i].nxt) {
int v = e[i].to;
if (vis[v] == ) tarjan(v);
if (vis[v] == ) low[u] = min(low[u], low[v]);
}
if (dfn[u] == low[u]) {
sig++;
do {
col[sta[tt]] = sig;
vis[sta[tt]] = -;
} while (sta[tt--] != u);
}
} void cal() {
cnt = ;
sig = ;
tt = -;
memset(dfn, , sizeof(dfn));memset(col, , sizeof(col));memset(vis, , sizeof(vis));
memset(sta, , sizeof(sta));memset(low, , sizeof(low));memset(deg, , sizeof(deg));
memset(contz, 0x3f3f3f3f, sizeof(contz));
for (int i = ; i < n; i++) if (!vis[i]) tarjan(i);
for (int i = ; i < cont; i++) {
int u = e[i].f;
int v = e[i].to;
if (col[u] != col[v]) deg[col[v]]++;
}
for (int i = ; i < n; i++) if (!deg[col[i]]) contz[col[i]] = min(contz[col[i]], a[i].c);
int ans = ; for (int i = ; i <= sig; i++) if (!deg[i]) ans += contz[i];
pi(ans);
} int main() {
int t;
ci(t);
for (int ii = ; ii <= t; ii++) {
ci(n);
for (int i = ; i < n; i++) scanf("%d%d%d%d", &a[i].x, &a[i].y, &a[i].r, &a[i].c);
cont = ;
memset(hea, -, sizeof(hea));
for (int i = ; i < n; i++) {
for (int j = ; j < n; j++) {
ll tmp = a[i].x - a[j].x;
ll tmp2 = a[i].y - a[j].y;
ll d1 = tmp * tmp + tmp2 * tmp2;
ll d2 = 1ll * a[i].r * a[i].r;
if (d1 <= d2) add(i, j);
}
}
printf("Case #%d: ", ii);
cal();
}
return ;
} ```
#include<bits/stdc++.h>
//#include<regex>
#define db double
#include<vector>
#define ll long long
#define vec vector<ll>
#define Mt vector<vec>
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
#define MP make_pair
#define PB push_back
#define inf 0x3f3f3f3f3f3f3f3f
#define fr(i, a, b) for(int i=a;i<=b;i++)
const int N = 4e6 + ;
const int mod = 1e9 + ;
const int MOD = mod - ;
const db eps = 1e-;
const db PI = acos(-1.0);
using namespace std;
struct P {
int f, to, nxt;
} e[N]; struct PP {
int x, y, r, c;
} a[N];
int hea[];
int n, cnt, sig, tt, cont;
int deg[], sta[], col[], vis[], low[], dfn[], need[], contz[]; void add(int f, int to) {//建边
e[cont].to = to;
e[cont].f = f;
e[cont].nxt = hea[f];
hea[f] = cont++;
} void tarjan(int u) {//强联通分量
vis[u] = ;
low[u] = dfn[u] = cnt++;
sta[++tt] = u;
for (int i = hea[u]; i != -; i = e[i].nxt) {
int v = e[i].to;
if (vis[v] == ) tarjan(v);
if (vis[v] == ) low[u] = min(low[u], low[v]);
}
if (dfn[u] == low[u]) {
sig++;
do {
col[sta[tt]] = sig;
vis[sta[tt]] = -;
} while (sta[tt--] != u);
}
} void cal() {
cnt = ;
sig = ;
tt = -;
memset(dfn, , sizeof(dfn));memset(col, , sizeof(col));memset(vis, , sizeof(vis));
memset(sta, , sizeof(sta));memset(low, , sizeof(low));memset(deg, , sizeof(deg));
memset(contz, 0x3f3f3f3f, sizeof(contz));
for (int i = ; i < n; i++) if (!vis[i]) tarjan(i);
for (int i = ; i < cont; i++) {
int u = e[i].f;
int v = e[i].to;
if (col[u] != col[v]) deg[col[v]]++;
}
for (int i = ; i < n; i++) if (!deg[col[i]]) contz[col[i]] = min(contz[col[i]], a[i].c);
int ans = ; for (int i = ; i <= sig; i++) if (!deg[i]) ans += contz[i];
pi(ans);
} int main() {
int t;
ci(t);
for (int ii = ; ii <= t; ii++) {
ci(n);
for (int i = ; i < n; i++) scanf("%d%d%d%d", &a[i].x, &a[i].y, &a[i].r, &a[i].c);
cont = ;
memset(hea, -, sizeof(hea));
for (int i = ; i < n; i++) {
for (int j = ; j < n; j++) {
ll tmp = a[i].x - a[j].x;
ll tmp2 = a[i].y - a[j].y;
ll d1 = tmp * tmp + tmp2 * tmp2;
ll d2 = 1ll * a[i].r * a[i].r;
if (d1 <= d2) add(i, j);
}
}
printf("Case #%d: ", ii);
cal();
}
return ;
}
HDU 5934 强联通分量的更多相关文章
- HDU 5934 (强连同分量+缩点)
题意: 给出n个炸弹的信息 :坐标x , 坐标y , 爆炸半径 , 成本: 如果一个炸弹被引爆那这个范围的都爆炸 , 问最小的成本是多少? 题意:首先先来个n^2 暴力出某个炸弹爆炸波及的其他炸弹,用 ...
- hdu 1269 (强联通分量Tarjan入门)
迷宫城堡 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 1269 迷宫城堡 【强联通分量(模版题)】
知识讲解: 在代码里我们是围绕 low 和 dfn 来进行DFS,所以我们务必明白 low 和 dfn 是干什么的? 有什么用,这样才能掌握他. 1. dfn[] 遍历到这个点的时间 2. ...
- HDU 4685 Prince and Princess(二分匹配+强联通分量)
题意:婚配问题,但是题目并不要求输出最大匹配值,而是让我们输出,一个王子可以与哪些王妃婚配而不影响最大匹配值. 解决办法:先求一次最大匹配,如果有两个已经匹配的王妃,喜欢她们两个的有两个或者以上相同的 ...
- 【强联通图 | 强联通分量】HDU 1269 迷宫城堡 【Kosaraju或Tarjan算法】
为了训练小希的方向感,Gardon建立了一座大城堡,里面有N个房间(N<=10000)和M条通道(M<=100000),每个通道都是单向的,就是说若称某通道连通了A房间和B房间,只说明 ...
- Kosaraju算法---强联通分量
1.基础知识 所需结构:原图.反向图(若在原图中存在vi到vj有向边,在反向图中就变为vj到vi的有向边).标记数组(标记是否遍历过).一个栈(或记录顶点离开时间的数组). 算法描叙: :对 ...
- [CF #236 (Div. 2) E] Strictly Positive Matrix(强联通分量)
题目:http://codeforces.com/contest/402/problem/E 题意:给你一个矩阵a,判断是否存在k,使得a^k这个矩阵全部元素都大于0 分析:把矩阵当作01矩阵,超过1 ...
- UVa 11324 & 强联通分量+DP
题意: 一张无向图,求点集使其中任意两点可到达. SOL: 强联通分量中的点要么不选要么全都选,然后缩点DAG+DP 记录一下思路,不想写了...代码满天飞.
- BZOJ 1051 & 强联通分量
题意: 怎么说呢...这种题目有点概括不来....还是到原题面上看好了... SOL: 求出强联通分量然后根据分量重构图,如果只有一个点没有出边那么就输出这个点中点的数目. 对就是这样. 哦还有论边双 ...
随机推荐
- 【C#多线程编程实战笔记】二、 线程同步
使用Mutex类-互斥锁 owned为true,互斥锁的初始状态就是被主线程所获取,否则处于未获取状态 name为定义的互斥锁名称,在整个操作系统只有一个命名未CSharpThreadingCookb ...
- EF增删改查+使用Expression进行动态排序分页
注:以下部分来自<ASP.NET MVC 企业级实战>一书的摘抄和改写以及部分个人学习心得. EF简单增删改查 增加 public static int Add() { using (No ...
- TitleLayout——一个Android轻松实现标题栏的库
TitleLayout 多功能.通用的.可在布局或者使用Java代码实现标题栏: 支持沉浸式状态栏: 支持左侧返回按钮不需要手动实现页面返回: 支持左侧按钮,中间标题,右边按钮点击 左侧支持图片+文字 ...
- CSS3动画效果之animation
先解决上一篇的遗留问题. div { width: 300px; height: 200px; background-color: red; -webkit-animation: test1 2s; ...
- Python中os和shutil模块实用方法集锦
Python中os和shutil模块实用方法集锦 类型:转载 时间:2014-05-13 这篇文章主要介绍了Python中os和shutil模块实用方法集锦,需要的朋友可以参考下 复制代码代码如下: ...
- Nginx做文件下载服务器
这是最简单的一种办法,贴完代码就能用 server { listen 80; charset utf-8; server_name localhost; root /data/file/; autoi ...
- Swing-JMenu菜单用法-入门
菜单是Swing客户端程序不可获取的一个组件.窗体菜单大致由菜单栏.菜单和菜单项三部分组成,如下图所示: 由图可见,对于一个窗体,首先要添加一个JMenuBar,然后在其中添加JMenu,在JMenu ...
- 201521123009 《Java程序设计》第6周学习总结
1. 本周学习总结 2. 书面作业 Q1:clone方法 1.1 Object对象中的clone方法是被protected修饰,在自定义的类中覆盖clone方法时需要注意什么? 用protected修 ...
- PTA分享码-Java
主要用于Java语法练习,非竞赛类题目. 1. Java入门 959dbf0b7729daa61d379ec95fb8ddb0 2. Java基本语法 23bd8870e ...
- json:JSONObject包的具体使用(JSONObject-lib包是一个beans,collections,maps,java arrays和xml和JSON互相转换的包)
1.JSONObject介绍 JSONObject-lib包是一个beans,collections,maps,java arrays和xml和JSON互相转换的包. 2.下载jar包 http:// ...