hdu 5934 Bomb
Bomb
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
#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的更多相关文章
- HDU 5934 Bomb(炸弹)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU 5934 Bomb 【图论缩点】(2016年中国大学生程序设计竞赛(杭州))
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 5934 Bomb(tarjan/SCC缩点)题解
思路:建一个有向图,指向能引爆对象,把强连通分量缩成一点,只要点燃图中入度为0的点即可.因为入度为0没人能引爆,不为0可以由别人引爆. 思路很简单,但是早上写的一直错,改了半天了,推倒重来才过了... ...
- 【(最小权点基)tarjan强连通分量缩点+tarjan模板】HDU 5934 Bomb
[AC] #include<bits/stdc++.h> using namespace std; typedef long long ll; int n; ; ; const int i ...
- 数位DP入门之hdu 3555 Bomb
hdu 3555 Bomb 题意: 在1~N(1<=N<=2^63-1)范围内找出含有 ‘49’的数的个数: 与hdu 2089 不要62的区别:2089是找不不含 '4'和 '62'的区 ...
- HDU 3622 Bomb Game(2-sat)
HDU 3622 Bomb Game 题目链接 题意:求一个最大半径,使得每一个二元组的点任选一个,能够得到全部圆两两不相交 思路:显然的二分半径,然后2-sat去判定就可以 代码: #include ...
- HDU 5934:Bomb(强连通缩点)
http://acm.hdu.edu.cn/showproblem.php?pid=5934 题意:有N个炸弹,每个炸弹有一个坐标,一个爆炸范围和一个爆炸花费,如果一个炸弹的爆炸范围内有另外的炸弹,那 ...
- 【HDU 5934】Bomb(强连通缩点)
Problem Description There are N bombs needing exploding. Each bomb has three attributes: exploding r ...
- Bomb HDU - 5934 (Tarjan)
#include<map> #include<set> #include<ctime> #include<cmath> #include<stac ...
随机推荐
- 如何使Android应用开机时自动启动
先记下来,主要是继承BroadcastReceiver实现.还有开机自动启动service的,好像是继承 IntentReceiver,不知道有什么不一样,有时间试试. 一: 简单 Android也有 ...
- spring技术核心概念纪要
一.背景 springframework 从最初的2.5版本发展至今,期间已经发生了非常多的修正及优化.许多新特性及模块的出现,使得整个框架体系显得越趋庞大,同时也带来了学习及理解上的困难. 本文阐述 ...
- NodeJs http.get 方法请求时间过长问题处理!
NodeJs 获取网页内容 http.get 默认请求超时过长了,程序要卡死好一会. 根据网上资料现改造了一个带超时设置的获取网页内容方法. 主要方法使用 setTimeout 来超时, 代码如下: ...
- U盘安装Win7操作系统
玩转Windows7系统镜像四部曲 Step 1: 下载Win7 ISO系统镜像 温馨提示:请您尽量选用Win7之家提供的官方原版镜像安装,因为正版比各种所谓的"精简版.纯净版" ...
- PDO多种方式取得查询结果
PDO多种方式取得查询结果 01 December 2009 1:26 Tuesday by Sjolzy PDO最大的特点之一是它的灵活性,本节将介绍如何取得查询结果,包括: 数组(数值或关联数组) ...
- 将WeX5部署到自己的Tomcat服务器上
页面服务UIServer布署 WeX5自带页面服务UIServer的是标准Web应用,可以部署在Java Web应用服务器上.下面介绍如何在Tomcat和WebLogic中部署WeX5的UIServe ...
- ThinkPad E440 Ubuntu 13.1无线网卡 RTL8723BE 驱动解决办法总结
方法一.在使用网线链接到情况下 第一步.执行下边到命令,即从github上下载驱动程序并安装 sudo apt-get install linux-headers-generic build-esse ...
- CRM JS 设置lookup字段 setSimpleLookupValue
function setSimpleLookupValue(LookupId, Type, Id, Name) { /// <summary> /// Sets the value for ...
- css学习笔记(5)
<style>*{margin:0; padding:0;}ul{ list-style:none;}li{ height:30px; width:100px; background:#F ...
- Android 获取设备信息 异常
/**获取设备信息 * @param c * @return */ public static void setDeviceInfo(Context c,RequestParams params){ ...