zoukankan      html  css  js  c++  java
  • hdu 5934 Bomb

    Bomb

    Problem Description
    There are N bombs needing exploding.

    Each bomb has three attributes: exploding radius ri, position (xi,yi) and lighting-cost ci which means you need to pay 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.
     
    Input
    First line contains an integer T, which indicates the number of test cases.

    Every test case begins with an integers N, which indicates the numbers of bombs.

    In the following N lines, the ith line contains four intergers xiyiri and ci, indicating the coordinate of ith bomb is (xi,yi), exploding radius is ri and lighting-cost is ci.

    Limits
    1T20
    1N1000
    108xi,yi,ri108
    1ci104
     
    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
     
    #include<cstdio>
    #include<cstring>
    #include<stack>
    #include<cmath>
    #include<vector>
    #include<algorithm>
    #define pb push_back
    using namespace std;
    typedef long long LL;
    struct Bomb
    {
        LL x,y,r;
        int c;
    }b[1005];
    vector<int>G[1005];
    int minc[1005],in[1005],pre[1005],lowlink[1005],sccno[1005],dfs_clock,scc_cnt,n;
    stack<int>S;
    bool jud(Bomb a,Bomb b)
    {
        return sqrt((a.x-b.x)*(a.x-b.x)*1.0+(a.y-b.y)*(a.y-b.y)*1.0)<=a.r*1.0;
    }
    void dfs(int u)
    {
        pre[u]=lowlink[u]=++dfs_clock;
        S.push(u);
        for(int i=0;i<G[u].size();i++)
        {
            int v=G[u][i];
            if(!pre[v])
            {
                dfs(v);
                lowlink[u]=min(lowlink[u],lowlink[v]);
            }
            else if(!sccno[v])
                lowlink[u]=min(lowlink[u],pre[v]);
        }
        if(lowlink[u]==pre[u])
        {
            scc_cnt++;
            while(1)
            {
                int x=S.top();
                S.pop();
                sccno[x]=scc_cnt;
                minc[scc_cnt]=min(minc[scc_cnt],b[x].c);
                if(x==u)break;
            }
        }
    }
    void find_scc()
    {
        dfs_clock=scc_cnt=0;
        memset(sccno,0,sizeof(sccno));
        memset(pre,0,sizeof(pre));
        for(int i=0;i<=n;i++)minc[i]=1e5;
        for(int i=0;i<n;i++)if(!pre[i])dfs(i);
    }
    int solve()
    {
        memset(in,0,sizeof(in));
        for(int i=0;i<n;i++)
            for(int j=0;j<G[i].size();j++)
                if(sccno[i]!=sccno[G[i][j]])
                    in[sccno[G[i][j]]]++;
        int res=0;
        for(int i=1;i<=scc_cnt;i++)
            if(in[i]==0)res+=minc[i];
        return res;
    }
    int main()
    {
        int T;
        scanf("%d",&T);
        for(int kase=1;kase<=T;kase++)
        {
            scanf("%d",&n);
            for(int i=0;i<n;i++)
                scanf("%lld%lld%lld%d",&b[i].x,&b[i].y,&b[i].r,&b[i].c);
            for(int i=0;i<n;i++)G[i].clear();
            for(int i=0;i<n;i++)
                for(int j=0;j<n;j++)
                    if(i!=j&&jud(b[i],b[j]))
                        G[i].pb(j);
            find_scc();
            printf("Case #%d: %d
    ",kase,solve());
        }
        return 0;
    }
  • 相关阅读:
    2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016) B
    openJudge C17K:Lying Island
    拓扑排序
    cdoj1638 红藕香残玉簟秋,轻解罗裳,独上兰舟。
    poj3159 Candies
    poj1364 King
    Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game
    Codeforces Round #416 (Div. 2) C. Vladik and Memorable Trip
    Codeforces Round #416 (Div. 2) B. Vladik and Complicated Book
    hdu4417 Super Mario
  • 原文地址:https://www.cnblogs.com/homura/p/6023101.html
Copyright © 2011-2022 走看看