HDU - 5934(73/600)

here 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.
Input
First 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≤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

tarjan以后找根

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long 
int liantong[1001], dfn[1001], low[1001], clj = 0, jc = 0;
stack<int>zz;
int inf=0x3f3f3f3f3f3f3f3f;
int T,n,x[1001],y[1001],r[1001],c[1001],u=0,chu[1001],dan[1001];
vector<int>tu[1001];
void tarjan(int xianzai)
{
    dfn[xianzai] = low[xianzai] = ++clj;
    zz.push(xianzai);
    for (int a = 0;a<tu[xianzai].size();a++)
    {
        int dd = tu[xianzai][a];
        if (!dfn[dd])
        {
            tarjan(dd);
            low[xianzai] = min(low[xianzai], low[dd]);
        }
        else if (!liantong[dd])low[xianzai] = min(low[xianzai], low[dd]);
    }
    if (low[xianzai] == dfn[xianzai])
    {
        jc++;
        for (;;)
        {
            int ww = zz.top();
            zz.pop();
            liantong[ww] = jc;
            if (ww == xianzai)break;
        }
    }
}
main()
{
    cin>>T;
    while(T--)
    {
        cin>>n;
        memset(dfn,0,sizeof(dfn));
        memset(low,0,sizeof(low));
        memset(liantong,0,sizeof(liantong));
        memset(r,0,sizeof(r));
        memset(c,0,sizeof(c));
        memset(chu,0,sizeof(chu));
        memset(dan,0x3f,sizeof(dan));
        clj=jc=0;
        while(!zz.empty())zz.pop();
        for(int a=1;a<=n;a++)tu[a].clear();
        for(int a=1;a<=n;a++)scanf("%lld%lld%lld%lld",&x[a],&y[a],&r[a],&c[a]);
        for(int a=1;a<=n;a++)
        {
            for(int b=1;b<=n;b++)
            {
                if(b==a)continue;
                if((x[b]-x[a])*(x[b]-x[a])+(y[a]-y[b])*(y[a]-y[b])>r[a]*r[a])continue;
                tu[a].push_back(b);
            }
        }
        for(int a=1;a<=n;a++)
        {
            if(liantong[a])continue;
            tarjan(a);
        }
        for(int a=1;a<=n;a++)
        {
            for(int b=0;b<tu[a].size();b++)
            {
                int w=tu[a][b];
                if(liantong[a]==liantong[w])continue;
                chu[liantong[w]]++;
            }
        }
        for(int a=1;a<=n;a++)
        {
            if(chu[liantong[a]])continue;
            dan[liantong[a]]=min(dan[liantong[a]],c[a]);
        //  cout<<liantong[a]<<endl;
        }
        /*for(int a=1;a<=jc;a++)
        {
            cout<<chu[a]<<endl;
        }
        return 0;*/
        int dandan=0;
        for(int a=1;a<=jc;a++)
        {
            if(dan[a]==inf)continue;
            if(chu[a])continue;
            dandan+=dan[a];
        }
        printf("Case #%lld: %lld\n",++u,dandan);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值