HDU-5934 Bomb(tarjan缩点+入度0最小和)
2018-03-22 21:23
375 查看
Bomb
There are NN bombs needing exploding.Each bomb has three attributes: exploding radius riri, position (xi,yi)(xi,yi) and lighting-cost cici which means you need to pay cici 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.InputFirst line contains an integer TT, which indicates the number of test cases.
Every test case begins with an integers NN, which indicates the numbers of bombs.
In the following NN lines, the ith line contains four intergers xixi, yiyi, riri and cici, indicating the coordinate of ith bomb is (xi,yi)(xi,yi), exploding radius is riri and lighting-cost is cici.
Limits
- 1≤T≤201≤T≤20
- 1≤N≤10001≤N≤1000
- −108≤xi,yi,ri≤108−108≤xi,yi,ri≤108
- 1≤ci≤1041≤ci≤104OutputFor 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 4Sample Output
Case #1: 15题目大概意思:输入t组数据,每组第一行输入一个n 接下来输入一个坐标x,y以及半径r 和引爆代价cost
我们需要引爆所有的点。连锁的点能不消耗代价引爆。然后计算引爆所有点的最少代价.思路:先按能连锁的点建图,然后tarjan缩点,求出所有入度为0的点。然后更新最小代价。最后求和n个点的最少代价。
写了接近一个小时,开始数组开小T了两次,然后因为scc_cnt忘记置0WA一次。题目总体还是比较容易 蒟蒻...哎
代码如下:#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#include<stack>
#include<list>
#include<set>
#include<map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define P pair<int ,int >
#define se second
#define fr frist
#define LL long long int
const int maxn=3500+10;
const int INF = 0x3f3f3f3f3f;
int Next[maxn*maxn],Lext[maxn],To[maxn*maxn],dis[maxn];
int dfn[maxn],low[maxn],scc[maxn],instc[maxn],cost[maxn],in[maxn],stc[maxn];
int top,times,cnt,scc_cnt,n;
struct node
{
int x,y,r;
} p[maxn];
void init()
{
cnt=top=times=scc_cnt=0;
mem(dfn,0);
mem(low,0);
mem(Lext,-1);
mem(scc,0);
mem(instc,0);
mem(in,0);
mem(stc,0);
mem(cost,0);
mem(dis,INF);
mem(in,0);
}
void add(int u,int v)
{
Next[++cnt]=Lext[u];
Lext[u]=cnt;
To[cnt]=v;
}
int dfs(int u)
{
dfn[u]=low[u]=++times;
stc[++top]=u;
instc[u]=1;
for(int i=Lext[u]; i!=-1; i=Next[i])
{
int v=To[i];
if(!dfn[v])
{
dfs(v);
low[u]=min(low[u],low[v]);
}
else if(instc[v])
low[u]=min(low[u],dfn[v]);
}
if(dfn[u]==low[u])
{
scc_cnt++;
while(true)
{
int x=stc[top--];
scc[x]=scc_cnt;
instc[x]=0;
if(x==u) break;
}
}
}
void tarjan()
{
int i;
for(i=1; i<=n; i++)
if(!dfn[i]) dfs(i);
for(i=1;i<=n;i++)
{
for(int j=Lext[i];j!=-1;j=Next[j])
{
int v=To[j];
if(scc[v]!=scc[i])
in[scc[v]]++;
}
}
for(i=1;i<=n;i++)
{
if(in[scc[i]]==0)
dis[scc[i]]=min(dis[scc[i]],cost[i]);
}
int output=0;
for(i=1;i<=scc_cnt;i++)
{
if(in[i]==0)
output+=dis[i];
}
printf("%d\n",output);
}
int main()
{
int t,k=1;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
init();
for(int i=1; i<=n; i++)
{
scanf("%d %d %d %d",&p[i].x,&p[i].y,&p[i].r,&cost[i]);
}
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
{
LL X=p[i].x-p[j].x;
LL Y=p[i].y-p[j].y;
LL R=p[i].r;
if(X*X+Y*Y<=R*R)
{
//cout<<i<<" "<<j<<endl;
add(i,j);
}
}
printf("Case #%d: ",k++);
tarjan();
}
}
相关文章推荐
- hdu 5934 Bomb【最小点基----Tarjan强连通+缩点染色】
- 【(最小权点基)tarjan强连通分量缩点+tarjan模板】HDU 5934 Bomb
- HDU 5934 Bomb (tarjan缩点)
- HDU 5934 Bomb(tarjan缩点)
- -----tarjan强连通分量缩点-hdu 5934 -Bomb
- hdu 3861(tarjan 缩点 + 二分图匹配 求最小路径覆盖
- hdu 5934-建图+tarjan缩点
- HDU 5934 Bomb【强联通缩点Tarjian】
- HDU-5934 Bomb 缩点
- Tarjan 缩点——HDU 5934
- [hdu 5934 Bomb]Tarjan强连通分量
- 【2016-CCPC-B】强连通分量,tarjan(Bomb,hdu 5934)
- HDU 3861 The King’s Problem(tarjan缩点+最小路径覆盖ISAP)
- HDU 1827 - Summer Holiday(Tarjan + 缩点 + 计算入度)
- HDU 5934 Bomb 【图论缩点】(2016年中国大学生程序设计竞赛(杭州))
- HDU 5934 Bomb 【图论缩点】(2016年中国大学生程序设计竞赛(杭州))
- HDU 5934 - Bomb(tarjan缩点+建图)
- 【HDU 5934】Bomb(强连通缩点)
- hdu 1827 Summer Holiday Tarjan缩点+度数判断 解题报告
- HDU --- 3861 The King’s Problem 【强联通缩点 + 最小路径覆盖】