• 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;
    }
  • 相关阅读:
    Maker DAO 与稳定币 Dai
    0x 协议治理体系,Part-2:Q&A
    Gnosis白皮书
    Digix:密码学资产中的黄金标准
    闪电网络主心骨——HTLC(哈希时间锁定)简介
    如何减少PDF文件的大小
    以太坊:创建 ERC-20 token
    Sublime Text 3 快捷键大全
    数据库学习第二季第三集:各种编程语言从数据库中获得数据方式小结
    数据库学习第二季第三集:各种编程语言从数据库中获得数据方式小结
  • 原文地址:https://www.cnblogs.com/homura/p/6023101.html
Copyright © 2020-2023  润新知