【题目描述】

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

【题目分析】
首先我们将问题转化为图论问题,我们按照能否引爆建图,我们肯定想点的是最前面的雷,即入度为0的雷。
可是有可能有环怎么办,我们将环用强连通分量缩成一个点,这样就变成了DAG图(有向无环图),然后找到入度为0 的点,点燃里面耗费最少的(强连通分量内部点燃一个其他的都会被引爆)
PS:PS:PS:最好养成一个固定的做题习惯,比如下标是从0开始还是从1开始等。这里就因为前面从0开始后面从1开始wa了两发。我觉得最好养成从1开始的习惯,虽然sort什么麻烦一点,但是容易理解,而且图论中也不容易出错,不容易越界等。

【AC代码】

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<climits>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;typedef long long ll;
const int MAXN=1e3+5;
const int MAXM=2e6+5;
struct boom
{int x,y,r,c;
}Boom[MAXN];
struct node
{int v,next;
}Edge[MAXM];
int head[MAXN],tot;
int DFN[MAXN],LOW[MAXN];
int color[MAXN],cnt;
bool vis[MAXN];
int idx;
int stack[MAXN],top;
int In[MAXN];
int n,ans;void init()
{memset(head,0,sizeof(head)); tot=0;idx=0; memset(vis,0,sizeof(vis));memset(DFN,0,sizeof(DFN));memset(color,0,sizeof(color));cnt=0; top=0;memset(In,0,sizeof(In));
}bool Close(int i,int j)
{ll xi=Boom[i].x; ll yi=Boom[i].y;ll xj=Boom[j].x; ll yj=Boom[j].y;ll dis=Boom[i].r;return dis*dis>=(xi-xj)*(xi-xj)+(yi-yj)*(yi-yj);
}void AddEdge(int u,int v)
{tot++;Edge[tot].v=v; Edge[tot].next=head[u];head[u]=tot;
}void read()
{int u,v;scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d%d%d%d",&Boom[i].x,&Boom[i].y,&Boom[i].r,&Boom[i].c);}for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){if(i==j) continue;if(Close(i,j)) AddEdge(i,j);}}
}void Trajan(int x)
{int v,tmp;DFN[x]=LOW[x]=++idx;stack[++top]=x; vis[x]=true;for(int i=head[x];i;i=Edge[i].next){v=Edge[i].v;if(!DFN[v]){Trajan(v);if(LOW[v]<LOW[x]) LOW[x]=LOW[v];}else if(vis[v] && LOW[v]<LOW[x]){LOW[x]=LOW[v];}}if(DFN[x]==LOW[x]){cnt++;do{tmp=stack[top--];vis[tmp]=false;color[tmp]=cnt;}while (tmp!=x);}
}void solve()
{int v;for(int i=1;i<=n;i++){if(!DFN[i])Trajan(i);}for(int i=1;i<=n;i++){for(int j=head[i];j;j=Edge[j].next){v=Edge[j].v;if(color[i]!=color[v])In[color[v]]++;}}ans=0;int minc;for(int i=1;i<=cnt;i++){if(!In[i]){minc=INT_MAX;for(int j=1;j<=n;j++){if(color[j]==i && Boom[j].c<minc){minc=Boom[j].c;}}ans+=minc;//printf("test: ans=%d minc=%d\n",ans,minc);}}
}int main()
{int T;scanf("%d",&T);for(int Case=1;Case<=T;Case++){init();read();solve();printf("Case #%d: %d\n",Case,ans);}return 0;
}

HDU 5934:Boom——强连通分量+缩点相关推荐

  1. The King’s Problem(tarjan求强连通分量缩点+匈牙利求有向无环图的最小路径覆盖)

    Link:http://acm.hdu.edu.cn/showproblem.php?pid=3861 The King's Problem Time Limit: 2000/1000 MS (Jav ...

  2. POJ1236Network of Schools——强连通分量缩点建图

    [题目描述] A number of schools are connected to a computer network. Agreements have been developed among ...

  3. 【差分约束系统】【强连通分量缩点】【拓扑排序】【DAG最短路】CDOJ1638 红藕香残玉簟秋,轻解罗裳,独上兰舟。...

    题意: 给定n个点(点权未知)和m条信息:u的权值>=v的权值+w 求点权的极小解和极大解(无解则输出-1) 极小解即每个点的点权可能的最小值 极大解即每个点的点权可能的最大值 题解: 差分约束 ...

  4. Strongly connected HDU - 4635(tarjan+强连通分量)

    题意: 给一个简单有向图,让你加最多的边,使他还是一个简单有向图. 题目: Give a simple directed graph with N nodes and M edges. Please ...

  5. tarjan算法总结 (强连通分量+缩点+割点),看这一篇就够了~

    文章目录 一.tarjan求强连通分量 1:算法流程 2:模板 二.tarjan缩点 1:相关定义 2:算法流程 三.tarjan求割点.桥 1.什么是割点 2.割点怎么求? 3.割点tarjan模板 ...

  6. Tarjan算法超超超详解(ACM/OI)(强连通分量/缩点)(图论)(C++)

    本文将持续更新. I 前置芝士:深度优先搜索与边的分类 首先我们来写一段基本的DFS算法(采用链式前向星存图): bool vis[MAXN];void dfs(int u) {vis[u] = tr ...

  7. Jzoj P4253 QYQ在艾泽拉斯___强连通分量缩点+拓扑序dp

    题目大意: Q Y Q QYQ QYQ有 K K K次技能,每次可以从一个岛屿上闪现到另外一个岛屿上,每一个岛屿只能登上一次. Q Y Q QYQ QYQ能从任何一个城市开始旅程,也能在任何一个城市结 ...

  8. POJ 2186 Popular Cows(强连通分量缩点,Tarjan算法)

    [题目链接] http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=16578 [解题报告] 给你一个有向图,问你有多少个点可以被其它 ...

  9. POJ 1236 Network of Schools(强连通分量缩点求根节点和叶子节点的个数)

    Description: A number of schools are connected to a computer network. Agreements have been developed ...

最新文章

  1. fedora17 的 rc.local
  2. Docker - 安装
  3. 分离Exchange的OWA和Microsoft-Server-Activesync手机访问
  4. 经验分享:聊聊多人游戏同步那点事
  5. GNOME Shell Extensions开发介绍
  6. 谷歌开源3D舞蹈生成模型FACT,舞姿清奇!
  7. pycharm console日志如何输出到txt_日志记录——logging模块
  8. 二分查找 —— 有序数组不小于(不大于)某数的第一个(最后一个)元素
  9. 一些碰到的陌生的技术名词搜集(持续更新……)
  10. 20线程测试cpu性能软件,cpu测试工具(wPrime Benchmark)
  11. 【VHDL语言学习笔记(七)】 分频器
  12. VSCODE常用快捷键
  13. RH358配置电子邮件传输--配置仅发送电子邮件服务
  14. Java:珠穆朗玛峰
  15. 怎么修改图片的kb大小?如何缩小照片kb?
  16. Java集合详解4:HashMap和HashTable
  17. vb.net操作数据库之ACCESS(2)
  18. java结账_java结账系统
  19. 35 岁,真的是职场荣枯线 吗?
  20. 京东万象行驶证识别api

热门文章

  1. luogu P2516 [HAOI2010]最长公共子序列
  2. mock接口开发,excel(读,写,修改)
  3. HTML基础入门学习准备篇
  4. yii2阅读随笔14
  5. MyBatis ResultMap(2)
  6. SMO写的查看数据库信息的代码
  7. blue html中转换,Vue/Vue中Html和Markdown互相转换/README.md · bluemoon/LearningNotes - Gitee.com...
  8. java struts2 excel上传_文件上传方法,使用Struts2,实现Excel文件读取并写入数据库技术...
  9. 深度学习loss值变为0_利用TensorFlow2.0为胆固醇、血脂、血压数据构建时序深度学习模型(python源代码)...
  10. java 工作6年 面试_为什么不想搞Java了,6年经验去面试5分钟结束,现在Java面试为何这么难...