HDU5934 Bomb(2016杭州CCPC第二题)(强连通缩点)
Bomb
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 26 Accepted Submission(s): 10
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.
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
5
0 0 1 5
1 1 1 6
0 1 1 7
3 0 2 10
5 0 1 4
#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第二题)(强连通缩点)的更多相关文章
- 【GDOI 2016 Day1】第二题 最长公共子串
分析 首先,可以发现,区间是可以合并滴.把区间按左端点排序,对于两个区间[l1,r1].[l2,r2],当l1<=l2 and r1>=l2,那么,将它们合成一个新的区间[l1,r2].当 ...
- 2016/1/12 第一题 输出 i 出现次数 第二题 用for循环和if条件句去除字符串中空格 第三题不用endwith 实现尾端字符查询
import java.util.Scanner; public class Number { private static Object i; /* *第一题 mingrikejijavabu中字符 ...
- 【HDU 5934】Bomb(强连通缩点)
Problem Description There are N bombs needing exploding. Each bomb has three attributes: exploding r ...
- 05:统计单词数【NOIP2011复赛普及组第二题】
05:统计单词数 总时间限制: 1000ms 内存限制: 65536kB 描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次 ...
- 2016.1.4~2016.1.7真题回顾!-- HTML5学堂
2016.1.4~2016.1.7真题回顾!-- HTML5学堂 2015悄然而逝,崭新的2016随即而行!生活需要新鲜感,学习JavaScript的过程需要有成就感!成就感又是来自于每一天的不断练习 ...
- 常见面试第二题之什么是Context
今天的面试题,也就是我们常见面试题系列的第二题,我们来讲一讲android中的context.我相信大家android开发者一定对于这个context非常熟悉,肯定都有使用过,肯定没有没使用过的.但是 ...
- 《学习OpenCV》练习题第五章第二题abc
代码: #include <stdio.h> #include <opencv/highgui.h> #include <opencv/cv.h> #include ...
- 《学习OpenCV》练习题第四章第二题
#include <highgui.h> #include <cv.h> #pragma comment (lib,"opencv_calib3d231d.lib&q ...
- CSDN挑战编程——《金色十月线上编程比赛第二题:解密》
金色十月线上编程比赛第二题:解密 题目详情: 小强是一名学生, 同一时候他也是一个黑客. 考试结束后不久.他吃惊的发现自己的高等数学科目竟然挂了,于是他果断入侵了学校教务部站点. 在入侵的过程中.他发 ...
随机推荐
- Portlet和servlet的区别
相同之处 l 都是java技术开发的web组件 l 都是由特定的容器在管理 l 都可以动态产生各种内容 l 生命周期都是由容器管理 l 和客户端的交互通过request/response机制 不同之处 ...
- [Windows驱动]驱动包(Driver Packages)
在windows下安装一个驱动,我们你需要把所有需要的软件打包-称为驱动包.驱动包里包括系统提供的给所有设备类使用的一般安装工具,还包括了设备商提供的设备特定的组件.下面我们就来看看驱动包里具体需要哪 ...
- 2013年8月份第4周51Aspx源码发布详情
迷你桌面闹钟源码 2013-8-27 [VS2010]功能介绍:实现了定时闹钟的功能,可以设置闹钟最前端显示.感兴趣的可以下载学习. BR个人博客系统(课程设计)源码 2013-8-27 [VS2 ...
- 2013年7月份第2周51Aspx源码发布详情
FineOffice自动化办公(OA)源码 2013-7-12 [ VS2010 ]源码描述:此源码使用fineui开发,作为村居使用的系统,所以命名为fineoffice,其实你在此基础上扩成CR ...
- 极客DIY:廉价电视棒玩转GNSS-SDR,实现GPS实时定位
0×00 前言 GNSS是Global Navigation Satellite System的缩写.中文称作:全球卫星导航系统.全球导航卫星系统. GNSS泛指所有的卫星导航系统,包括全球的.区域的 ...
- php生成图片
//生成图片,第一个参数宽,第二个高 1.$image = imagecreatetruecolor(100,25); //生成颜色,当第一次调用生成颜色的方法,是生成背景颜色 2.$backgrou ...
- php大力力 [022节]php编程要有一种态度:渴望遇见麻烦
2015-08-27 php大力力022.php编程要有一种态度:渴望遇见麻烦 不能一遇到问题和麻烦,就烦躁焦躁. 写程序,写代码,调试实验就是天天遇见不可预期的错误bug,这是常态.老生常谈,要适应 ...
- HDU5437 Alisha’s Party 优先队列
点击打开链接 可能出现的问题: 1.当门外人数不足p人时没有判断队列非空,导致RE. 2.在m次开门之后最后进来到一批人没有入队. 3.给定的开门时间可能是打乱的,需要进行排序. #include&l ...
- NBU 2475 Survivors(RMQ线段树)
NBU 2475Survivors 题目链接:http://acm.nbu.edu.cn/v1.0/Problems/Problem.php?pid=2475 题意:给定n个人,每个人有strengt ...
- BUAA 724 晴天小猪的神题(RMQ线段树)
BUAA 724 晴天小猪的神题 题意:中文题,略 题目链接:http://acm.buaa.edu.cn/problem/724/ 思路:对于询问x,y是否在同一区间,可以转换成有没有存在一个区间它 ...