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);
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章