Bomb

Problem Description
There are N bombs needing exploding.

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.

 
Input
First line contains an integer T, which indicates the number of test cases.

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

 
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
1
5
0 0 1 5
1 1 1 6
0 1 1 7
3 0 2 10
5 0 1 4
 
Sample Output
Case #1: 15
 
#include<cstdio>
#include<cstring>
#include<stack>
#include<cmath>
#include<vector>
#include<algorithm>
#define pb push_back
using namespace std;
typedef long long LL;
struct Bomb
{
LL x,y,r;
int c;
}b[];
vector<int>G[];
int minc[],in[],pre[],lowlink[],sccno[],dfs_clock,scc_cnt,n;
stack<int>S;
bool jud(Bomb a,Bomb b)
{
return sqrt((a.x-b.x)*(a.x-b.x)*1.0+(a.y-b.y)*(a.y-b.y)*1.0)<=a.r*1.0;
}
void dfs(int u)
{
pre[u]=lowlink[u]=++dfs_clock;
S.push(u);
for(int i=;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++;
while()
{
int x=S.top();
S.pop();
sccno[x]=scc_cnt;
minc[scc_cnt]=min(minc[scc_cnt],b[x].c);
if(x==u)break;
}
}
}
void find_scc()
{
dfs_clock=scc_cnt=;
memset(sccno,,sizeof(sccno));
memset(pre,,sizeof(pre));
for(int i=;i<=n;i++)minc[i]=1e5;
for(int i=;i<n;i++)if(!pre[i])dfs(i);
}
int solve()
{
memset(in,,sizeof(in));
for(int i=;i<n;i++)
for(int j=;j<G[i].size();j++)
if(sccno[i]!=sccno[G[i][j]])
in[sccno[G[i][j]]]++;
int res=;
for(int i=;i<=scc_cnt;i++)
if(in[i]==)res+=minc[i];
return res;
}
int main()
{
int T;
scanf("%d",&T);
for(int kase=;kase<=T;kase++)
{
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%lld%lld%lld%d",&b[i].x,&b[i].y,&b[i].r,&b[i].c);
for(int i=;i<n;i++)G[i].clear();
for(int i=;i<n;i++)
for(int j=;j<n;j++)
if(i!=j&&jud(b[i],b[j]))
G[i].pb(j);
find_scc();
printf("Case #%d: %d\n",kase,solve());
}
return ;
}

hdu 5934 Bomb的更多相关文章

  1. HDU 5934 Bomb(炸弹)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  2. HDU 5934 Bomb 【图论缩点】(2016年中国大学生程序设计竞赛(杭州))

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  3. HDU 5934 Bomb(tarjan/SCC缩点)题解

    思路:建一个有向图,指向能引爆对象,把强连通分量缩成一点,只要点燃图中入度为0的点即可.因为入度为0没人能引爆,不为0可以由别人引爆. 思路很简单,但是早上写的一直错,改了半天了,推倒重来才过了... ...

  4. 【(最小权点基)tarjan强连通分量缩点+tarjan模板】HDU 5934 Bomb

    [AC] #include<bits/stdc++.h> using namespace std; typedef long long ll; int n; ; ; const int i ...

  5. 数位DP入门之hdu 3555 Bomb

    hdu 3555 Bomb 题意: 在1~N(1<=N<=2^63-1)范围内找出含有 ‘49’的数的个数: 与hdu 2089 不要62的区别:2089是找不不含 '4'和 '62'的区 ...

  6. HDU 3622 Bomb Game(2-sat)

    HDU 3622 Bomb Game 题目链接 题意:求一个最大半径,使得每一个二元组的点任选一个,能够得到全部圆两两不相交 思路:显然的二分半径,然后2-sat去判定就可以 代码: #include ...

  7. HDU 5934:Bomb(强连通缩点)

    http://acm.hdu.edu.cn/showproblem.php?pid=5934 题意:有N个炸弹,每个炸弹有一个坐标,一个爆炸范围和一个爆炸花费,如果一个炸弹的爆炸范围内有另外的炸弹,那 ...

  8. 【HDU 5934】Bomb(强连通缩点)

    Problem Description There are N bombs needing exploding. Each bomb has three attributes: exploding r ...

  9. Bomb HDU - 5934 (Tarjan)

    #include<map> #include<set> #include<ctime> #include<cmath> #include<stac ...

随机推荐

  1. Activity之间数据交流(onActivityResult的用法)

    http://www.blogjava.net/mixer-a/archive/2012/03/23/375014.html http://www.cnblogs.com/linjiqin/archi ...

  2. 三个loading小动画实例

    直接贴代码: <!DOCTYPE html><html><head>    <meta charset="utf-8">    &l ...

  3. 原创:cellmap 基站查询 for android

    cellmap for android 3.6.8.7.9.8 更新日期:2016年12月30日 特别声明:本软件不能进行手机定位,不能对手机号码定位,谨防被骗. 下载地址: cellmap3.6.8 ...

  4. testNG中同一个test节点上class的执行顺序

    如果每个class中都有setUp(),那么先执行所有class的setUp方法,之后再执行具体的测试方法.这样就导致只有最后一个测试能通过,其他测试都失败了. 具体设置如下图:

  5. linux shell:mysql bin_log定期清理脚本

    需求: 1.自动处理mysql bin日志脚本 2.输出可读log 3.保留1周的日志 4.对所有数据库统一处理.   实现过程描述:   思路:两种方式实现 1.mysql目录通过ls获取bin日志 ...

  6. ios实现屏幕旋转的方法

    1.屏蔽AppDelegate下面的屏幕旋转方法 #pragma mark - 屏幕旋转的 //- (UIInterfaceOrientationMask)application:(UIApplica ...

  7. Spring Boot构建RESTful API与单元测试

    如果您对Spring MVC不熟悉并且还没有尝试过快速入门案例,建议先看一下相关的内容. @Controller:修饰class,用来创建处理http请求的对象 @RestController:Spr ...

  8. 112、两个Activity切换黑屏问题

    <activity android:name=".main.select.ActDoyenActivity" android:screenOrientation=" ...

  9. 玩转单元测试之WireMock -- Web服务模拟器

    玩转单元测试之WireMock -- Web服务模拟器 WireMock 是一个灵活的库用于 Web 服务测试,和其他测试工具不同的是,WireMock 创建一个实际的 HTTP服务器来运行你的 We ...

  10. appium入门

    前语:学习需要总结,或许有些知识自己存在偏差,但是能总结出来就会更加加深所学知识 1.       环境变量配置 必备软件安装: jdk1.6.0 android-sdk python:2.7(3.6 ...