• Bomb


    Bomb

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 4098    Accepted Submission(s): 1264


    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 xi , yi , ri 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
     
    Source
     
    #include<bits/stdc++.h>
    #define REP(i, a, b) for(int i = (a); i <= (b); ++ i)
    #define REP(j, a, b) for(int j = (a); j <= (b); ++ j)
    #define PER(i, a, b) for(int i = (a); i >= (b); -- i)
    using namespace std;
    const int maxn=1e5+5;
    template <class T>
    inline void rd(T &ret){
        char c;
        ret = 0;
        while ((c = getchar()) < '0' || c > '9');
        while (c >= '0' && c <= '9'){
            ret = ret * 10 + (c - '0'), c = getchar();
        }
    }
    struct node{
         long long x,y,r,val;
    }p[maxn];
    int dfn[maxn],low[maxn],in[maxn],T,n,tot,pos[maxn],cnt,vis[maxn],w[maxn];
    vector<int>g[maxn];
    stack<int>sk;
    void tarjan(int cur){
         dfn[cur]=low[cur]=++tot;
         vis[cur]=1;
         sk.push(cur);
         for(int i=0;i<g[cur].size();i++){
              int to=g[cur][i];
              if(!dfn[to]){
                   tarjan(to);
                   low[cur]=min(low[cur],low[to]);
              }
              else if(vis[to])low[cur]=min(low[cur],dfn[to]);
         }
         if(dfn[cur]==low[cur]){
               cnt++;
               int now;
               do{
                    now=sk.top();
                    sk.pop();
                    pos[now]=cnt;
                    vis[now]=0;
                    w[cnt]=min(w[cnt],(int)p[now].val);
               }while(now!=cur);
         }
    }
    int main()
    {
        int many=1;
        rd(T);
        while(T--){
            rd(n);
            memset(dfn,0,sizeof(dfn));
            memset(low,0,sizeof(low));
            memset(in,0,sizeof(in));
            memset(w,127,sizeof(w));
            memset(vis,0,sizeof(vis));
            memset(pos,0,sizeof(pos));
            tot=0,cnt=0;
            REP(i,1,n)g[i].clear();
            REP(i,1,n){
                 scanf("%lld%lld%lld%lld",&p[i].x,&p[i].y,&p[i].r,&p[i].val);
                 for(int j=1;j<i;j++){
                      if((p[i].x-p[j].x)*(p[i].x-p[j].x)+(p[i].y-p[j].y)*(p[i].y-p[j].y)<=p[i].r*p[i].r){
                             g[i].push_back(j);
                      }
                      if((p[i].x-p[j].x)*(p[i].x-p[j].x)+(p[i].y-p[j].y)*(p[i].y-p[j].y)<=p[j].r*p[j].r){
                             g[j].push_back(i);
                      }
                 }
            }
            REP(i,1,n)if(!dfn[i])tarjan(i);
            REP(i,1,n){
               for(int j=0;j<g[i].size();j++){
                   int to=g[i][j];
                   if(pos[i]!=pos[to])in[pos[to]]++;
               }
            }
            long long ans=0;
            REP(i,1,cnt){
                if(!in[i])ans+=w[i];
            }
            cout<<"Case #"<<many++<<": ";
            cout<<ans<<endl;
        }
        return 0;
    }
  • 相关阅读:
    CodeForces 454C——数学——Little Pony and Expected Maximum
    7.23多校——5305DFS——Friends
    Codeforces Round #313 (Div. 2)——C数学题——Gerald's Hexagon
    Codeforces Round #313 (Div. 2)——D递归,stirng——Equivalent Strings
    Codeforces Round #312 (Div. 2)——C暴力技巧——Amr and Chemistry
    简单几何(线段覆盖) POJ 3347 Kadj Squares
    DP+BIT(优化复杂度) UESTC 1217 The Battle of Chibi
    DP(01背包) UESTC 1218 Pick The Sticks (15CCPC C)
    二叉树的前中后序遍历以及表达式树
    DP(优化) UVALive 6073 Math Magic
  • 原文地址:https://www.cnblogs.com/czy-power/p/10506402.html
Copyright © 2020-2023  润新知