There are
N
N bombs needing exploding.
Each bomb has three attributes: exploding radius ri ri, position (xi,yi) (xi,yi) and lighting-cost ci ci which means you need to pay ci 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 ri ri, position (xi,yi) (xi,yi) and lighting-cost ci ci which means you need to pay ci 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 N, which indicates the numbers of bombs.
In the following N N lines, the ith line contains four intergers xi xi, yi yi, ri ri and ci ci, indicating the coordinate of ith bomb is (xi,yi) (xi,yi), exploding radius is ri ri and lighting-cost is ci ci.
Limits
- 1≤T≤20 1≤T≤20
- 1≤N≤1000 1≤N≤1000
- −108≤xi,yi,ri≤108 −108≤xi,yi,ri≤108
- 1≤ci≤104 1≤ci≤104
1 5 0 0 1 5 1 1 1 6 0 1 1 7 3 0 2 10 5 0 1 4
Case #1: 15
题意:给若干炸弹,给你炸弹的坐标,炸弹爆炸的范围和引爆炸弹的代价,让你求出引爆所有的炸弹最少的代价
强联通分量tarjin
首先将某一炸弹爆炸可以引爆其他炸弹,建图,然后跑tarjin
代码如下:
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
const int N=1e3+5;
const int INF=1e6+8;
struct Edge{
int to,next;
}edge[N*N];
int head[N],dfn[N],low[N],instack[N],Stack[N],in[N],belong[N];
int num,top,dfs_time,k;
ll x[N],y[N],r[N],c[N];
void init()
{
memset(head,-1,sizeof(head));
memset(dfn,0,sizeof(dfn));
memset(in,0,sizeof(in));
memset(instack,0,sizeof(instack));
num=0,k=0,top=0,dfs_time=0;
}
void add(int i,int j)
{
edge[k].to=j;
edge[k].next=head[i];
head[i]=k++;
}
void tarjan(int start)
{
dfn[start]=low[start]=++dfs_time;
Stack[top++]=start;
instack[start]=1;
for(int i=head[start];i!=-1;i=edge[i].next)
{
int to=edge[i].to;
if(!dfn[to])
{
tarjan(to);
low[start]=min(low[start],low[to]);
}
else if(instack[to])
low[start]=min(low[start],dfn[to]);
}
if(low[start]==dfn[start])
{
int to;
num++;
do{
to=Stack[--top];
instack[to]=0;
belong[to]=num;
}while(start!=to);
}
}
int main()
{
int t,n,count=1;
scanf("%d",&t);
while(t--)
{
init();
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%lld%lld%lld%lld",&x[i],&y[i],&r[i],&c[i]);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(i!=j)
if(sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]))<=r[i])//i能引爆j
add(i,j);
for(int i=1;i<=n;i++)
if(!dfn[i])
tarjan(i);
for(int i=1;i<=n;i++)
{
for(int j=head[i];j!=-1;j=edge[j].next)
{
int to=edge[j].to;
if(belong[i]==belong[to]) continue;
in[belong[to]]++;
}
}
ll minn1=0;
for(int i=1;i<=num;i++)
{
if(!in[i])
{
ll minn=INF;
for(int j=1;j<=n;j++)
if(belong[j]==i)
minn=min(minn,c[j]);
minn1+=minn;
}
}
printf("Case #%d: %lld\n",count++,minn1);
}
return 0;
}