[CCPC杭州] Bomb 强连通分量
来源:互联网 发布:松江3208联动编程软件 编辑:程序博客网 时间:2024/04/27 22:37
Bomb
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1894 Accepted Submission(s): 631
Problem Description
There are N bombs needing exploding.
Each bomb has three attributes: exploding radiusri , 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.
Each bomb has three attributes: exploding radius
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.
Input
First line contains an integer T , which indicates the number of test cases.
Every test case begins with an integersN , which indicates the numbers of bombs.
In the followingN 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
Every test case begins with an integers
In the following
Limits
-
-
-
-
Output
For every test case, you should output 'Case #x: y', where x indicates the case number and counts from 1 and y is the minimum cost.
Sample Input
150 0 1 51 1 1 60 1 1 73 0 2 105 0 1 4
Sample Output
Case #1: 15
Source
2016年中国大学生程序设计竞赛(杭州)
Recommend
liuyiding
先利用强连通分量缩点,这样图就不存在环了,然后再直接引入度为0的点就好
#include<bits/stdc++.h>using namespace std;typedef long long ll;const int maxn = 1e5;const int INF = 1e9;vector<int> G[maxn];int pre[maxn],lowlink[maxn],sccno[maxn],dfs_clock,scc_cnt;stack<int> S;void dfs(int u){ pre[u] = lowlink[u] = ++dfs_clock; S.push(u); for(int i=0;i < G[u].size();i++) { int v = G[u][i]; if(!pre[v]) { dfs(v); lowlink[u] = min(lowlink[u],lowlink[v]); } else if(!sccno[v]) { lowlink[u] = min(lowlink[u],pre[v]); } } if(lowlink[u] == pre[u]) { scc_cnt++; for(;;) { int x = S.top(); S.pop(); sccno[x] = scc_cnt; if(x==u) break; } }}void find_scc(int n){ dfs_clock = scc_cnt = 0; memset(sccno,0,sizeof(sccno)); memset(pre,0,sizeof(pre)); for(int i = 0;i < n;i++) { if(!pre[i]) { dfs(i); } }}int n;ll x[1005];ll y[1005];ll r[1005];ll c[1005];ll getdis(int i,int j){ return (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]);}ll in[maxn];int T;ll nto[maxn];ll num[maxn];int main(){// freopen("data.txt","r",stdin); ios_base::sync_with_stdio(false); scanf("%d",&T); int cas=0; while(T--) { cas++; cout <<"Case #"<<cas<<": "; scanf("%d",&n); memset(in,0,sizeof(in)); memset(num,0,sizeof(num)); for(int i=0;i<=n;i++) { nto[i]=INF; G[i].clear(); } for(int i=0;i<n;i++) { scanf("%lld%lld%lld%lld",&x[i],&y[i],&r[i],&c[i]); } for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(j==i) continue; if(r[i]*r[i]>=getdis(i,j)) {// cout << i<<"->"<<j<<endl; G[i].push_back(j); } if(r[j]*r[j]>=getdis(i,j)) {// cout << j <<"->"<< i <<endl; G[j].push_back(i); } } } find_scc(n); for(int i=0;i<n;i++) { num[sccno[i]]++; nto[ sccno[i] ] = min(nto[ sccno[i] ],c[i]); } ll ans =0 ; for(int i=0;i<n;i++) { for(int j=0;j<G[i].size();j++) { if(sccno[G[i][j]]!=sccno[i]) in[ sccno[G[i][j]] ]++; } } for(int i=1;i<=scc_cnt;i++) { if(in[i]==0) { ans += nto[i]; } } cout << ans<<endl; } return 0;}
阅读全文
0 0
- [CCPC杭州] Bomb 强连通分量
- HDU 5934 && 2016CCPC杭州 B: Bomb(Trajan强连通)
- 【2016-CCPC-B】强连通分量,tarjan(Bomb,hdu 5934)
- [hdu 5934 Bomb]Tarjan强连通分量
- HDU5934 Bomb(强连通分量分解)
- HDU 5934 Bomb(强连通分量)
- HDOJ 5934 Bomb【2016杭州现场赛】【强连通】
- HDU 5934 Bomb(强连通分量缩点)
- HDU 5934 Bomb(强连通分量缩点)
- HDU-5934 Bomb(强连通分量缩点)
- -----tarjan强连通分量缩点-hdu 5934 -Bomb
- 【HDU】5934 Bomb 强连通分量+缩点
- HDU5934 Bomb 【强联通分量】
- 收缩强连通分量
- 强连通分量
- POJ2181强连通分量
- 强连通分量模板
- POJ_2762_强连通分量
- Atitit react 详细使用总结 绑定列表显示 attilax总结 1. 前言1 1.1. 资料数量在百度内的数量对比1 1.2. 版本16 v15.6.11 1.3. 引入js2
- Python 愚蠢的我
- 侧拉+上下拉动
- Atitit React的相关概念东东 attilax总结 v3
- Python error: Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat)解决方案
- [CCPC杭州] Bomb 强连通分量
- C语言中的回调函数
- java关于流的学习笔记大全,包含全部流的概念及用法
- 欢迎来到 Corda 的世界!
- 66. Plus One(第六周)
- jQuery源码之init函数的分析
- 侧拉加上下拉动刷新
- React、Vue项目上线的改善
- Java内部类使用总结