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;
    }
  • 相关阅读:
    《面试题 03.05. 栈排序》——惰性更新
    CTF<密码学> writeup 传统知识+古典密码
    有趣的数学(二)
    【】Dedecms友情链接去掉LI的方法介绍
    【】【】打工子弟学校学生们的中国梦何时圆?
    Discuz! 7.2 防注册机注册+发垃圾帖的解决方法
    Windows 8 常用快捷键
    Win7 64位系统下Auto CAD 2010注册激活,出现警告:Make sure you can write to current directory...
    怎么从EXCEL或WORD里提取图片?
    如何将windows xp系统下的outlook express6.0的邮件,帐号及通迅录导入Office Outlook xp/2003/2007中...
  • 原文地址:https://www.cnblogs.com/homura/p/6023101.html
Copyright © 2011-2022 走看看