Bomb

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

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
- 1≤T≤20
- 1≤N≤1000
- −108≤xi,yi,ri≤108
- 1≤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
 
Source
【总结】感觉自己智商就是一坨屎,当时在杭州比赛的时候,看到这道题,就想到了强连通分量,但我想的方向错了,我一直想着把一些互相可以到达的点缩成一个点或者找一棵树的根,却没有想到从缩点后点的入度下手,真是亏了我前段时间刷了好多强连通的题。哎 还是刷题太少,思路太狭窄而且比赛临场经验不足。真的很遗憾,我们当时是铁牌第一,我刚才照着模板敲了一下就过了,要是当时想到入度,就可以拿铜牌了。是该总结一下了,确实不能盲目刷题,还是要总结体型,拓展思路,不能再留下遗憾了。下面附上两个星期前就该A掉的代码。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#define inf 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof a)
typedef long long ll;
using namespace std;
const int N = 1005;
const int M = 24005;
int vis[N],dfn[N],low[N],head[N],stack1[N],num[N],in[N];
ll cost[N];
int n,m,tot,son,maxn,tim,top,cut;
ll ans;
struct EDG{int to,next;}edg[N*N];
struct node{ll x,y,r,c;}a[N];
bool cmp(node f,node g){return f.c<g.c;}
void add(int u,int v){
    edg[tot].to=v;edg[tot].next=head[u];head[u]=tot++;
}
void init(){
    met(head,-1);
    tot=tim=top=cut=0;
    met(vis,0);
    met(edg,0);
    met(in,0);
    met(cost,inf);
    met(stack1,0);met(num,0);met(dfn,0);met(low,0);
}
void Tarjan(int u) {
    int v;
    low[u] = dfn[u] = ++tim;
    stack1[top++] = u;
    vis[u] = 1;
    for(int e = head[u]; e != -1; e = edg[e].next){
        v = edg[e].to;
        if(!dfn[v]){
            Tarjan(v);
            low[u] = min(low[u], low[v]);
        }else if(vis[v]){
            low[u] = min(low[u], dfn[v]);
        }
    }
    if(low[u] == dfn[u]){
        cut++;
        do{
            v = stack1[--top];
            num[v] = cut;
            cost[cut]=min(cost[cut],a[v].c);
            vis[v] = 0;
        }while(u != v);
    }
}
int main() {
    int T;
    scanf("%d",&T);
    for(int t=1;t<=T;t++){
        init();
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%lld%lld%lld%lld",&a[i].x,&a[i].y,&a[i].r,&a[i].c);
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                if(i==j)continue;
                if((a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y)<=a[i].r*a[i].r){
                    add(i,j);
                }
            }
        }
        for(int i=1;i<=n;i++)if(!dfn[i])Tarjan(i);
        for(int i=1; i<=n; i++) {
            for(int j=head[i]; j!=-1; j=edg[j].next) {
                int v=edg[j].to;
                if(num[i]!=num[v])in[num[v]]++;
            }
        }
        ans=0;
        for(int i=1;i<=cut;i++){
            if(!in[i])ans+=cost[i];
        }
        printf("Case #%d: %lld\n",t,ans);
    }
    return 0;
}

HDU5934 Bomb(2016杭州CCPC第二题)(强连通缩点)的更多相关文章

  1. 【GDOI 2016 Day1】第二题 最长公共子串

    分析 首先,可以发现,区间是可以合并滴.把区间按左端点排序,对于两个区间[l1,r1].[l2,r2],当l1<=l2 and r1>=l2,那么,将它们合成一个新的区间[l1,r2].当 ...

  2. 2016/1/12 第一题 输出 i 出现次数 第二题 用for循环和if条件句去除字符串中空格 第三题不用endwith 实现尾端字符查询

    import java.util.Scanner; public class Number { private static Object i; /* *第一题 mingrikejijavabu中字符 ...

  3. 【HDU 5934】Bomb(强连通缩点)

    Problem Description There are N bombs needing exploding. Each bomb has three attributes: exploding r ...

  4. 05:统计单词数【NOIP2011复赛普及组第二题】

    05:统计单词数 总时间限制:  1000ms 内存限制:  65536kB 描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次 ...

  5. 2016.1.4~2016.1.7真题回顾!-- HTML5学堂

    2016.1.4~2016.1.7真题回顾!-- HTML5学堂 2015悄然而逝,崭新的2016随即而行!生活需要新鲜感,学习JavaScript的过程需要有成就感!成就感又是来自于每一天的不断练习 ...

  6. 常见面试第二题之什么是Context

    今天的面试题,也就是我们常见面试题系列的第二题,我们来讲一讲android中的context.我相信大家android开发者一定对于这个context非常熟悉,肯定都有使用过,肯定没有没使用过的.但是 ...

  7. 《学习OpenCV》练习题第五章第二题abc

    代码: #include <stdio.h> #include <opencv/highgui.h> #include <opencv/cv.h> #include ...

  8. 《学习OpenCV》练习题第四章第二题

    #include <highgui.h> #include <cv.h> #pragma comment (lib,"opencv_calib3d231d.lib&q ...

  9. CSDN挑战编程——《金色十月线上编程比赛第二题:解密》

    金色十月线上编程比赛第二题:解密 题目详情: 小强是一名学生, 同一时候他也是一个黑客. 考试结束后不久.他吃惊的发现自己的高等数学科目竟然挂了,于是他果断入侵了学校教务部站点. 在入侵的过程中.他发 ...

随机推荐

  1. Codeforces 235C

    题目大意: 给定一个字符串,接下来再给n个字符串,求原字符串中含有多少个当前给定字符串的循环同构体的字符串的个数 以初始字符串构建后缀自动机,在自动机上前进的时候,比如当前需要匹配的字符串为aba,到 ...

  2. PowerShell并发控制-命令行参数之四问

    传教士问: win下如何 获取进程命令行,及命令行参数? 传教士答: 可以用这个powershell命令(实际上是wmi查询): (get-wmiobject -query "select ...

  3. 使用AppCan自带的升级功能实现移动端升级

    1.需要在AppCan项目的config.xml文件中设置“更新地址”,即在执行uexWidget.checkUpdate();时访问的后台页面地址,比如: http://192.168.0.10:8 ...

  4. Android ScrollView与ViewPager滑动冲突

    前段时间做项目碰到在ScrollView里添加ViewPager,但是发现ViewPager的左右滑动和ScrollView的滑动冲突了,解决这个问题的方法是重写ScrollView. 代码: pub ...

  5. 标签navtab

    创建navtab 创建一个navtab有以下两种方式: 1.Data属性:DOM添加属性data-toggle="navtab"后,单击触发. a链接示例: <a href= ...

  6. Linux内核-链表

    linux内核链表的定义(定义了双向链表,不含数据域) 定义在 /linux-source-3.13.0/include/linux/types.h 头文件中. struct list_head { ...

  7. YAML 语言语法

    发现很多开源的软件的配置文件都使用了这种语言来描述,据说是简单强大,很不巧,ansible也使用了这种语言来描述配置,学习ansible之前,先学习一下YAML语言. YAML基本语法规则如下: 大小 ...

  8. FZU 2072 - Count

    题意:给一个数组,每次查询输出区间内数字x出现的次数. 每次查询数字x是与其它数字无关的,所以我们可以以每个数字为索引建立一个链表,里面存放它出现的下标,这里可以保证是递增的.每次查询数字x,就在x的 ...

  9. PAT 06-2 字符串字母大小写转换

    没什么好说的,记得使用ctype.h就好了,谭浩强那本书就介绍了,再不使用就太对不起他老人家了:有一点小小的地方需要注意一下,&&的优先级比=号高,所以getchar()两边没有括号的 ...

  10. hdu 2077

    PS:汉诺塔问题....找规律...观察发现,先是小的移动到B,然后大的移动到C(两步),然后小的移动到C,完成.刚开始就以为是f(n)=2f(n-1)+2..然而,小的移动一步是需要f(n)=3f( ...