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.
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.
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();
}
}