HDU 5934 Bomb(炸弹)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

 

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.
现有N颗炸弹急需引爆。

每颗炸弹有三个属性:爆炸半径ri,炸弹位置(xi, yi),还有起爆费用ci,即你需要花费ci才能引爆这个炸弹。

如果一颗未引爆的炸弹在另一颗炸弹的爆炸半径边缘或者其中,则会被连锁引爆。

此时你已得知所有炸弹的属性,用最小的花费引爆所有炸弹吧。

CN

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
第一行为一个整数T,表示测试用例的数量。

每个测试用例开头都有一个整数N,表示炸弹的数量。

随后N行,第i行有四个整数xi,yi,ri,与ci,表示第i个炸弹的坐标(xi,yi),爆炸半径ri与起爆费用ci。

数据范围
- ≤T≤
- ≤N≤
- −^≤xi, yi, ri≤^
- ≤ci≤^

CN

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.
对于每组测试用例,输出"Case #x: y",x表示从1开始的用例编号,y为最小费用。

CN

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

题解

  Tarjan缩点
  先根据每个炸弹的爆炸范围和坐标构造出一个有向图,然后再进行缩点。
  入度为0的点则为需要引爆的点,将其费用相加即是结果。

代码 C++

 #include <cstdio>
#include <algorithm>
#define ll __int64
#define mx 1005
int n, c[mx]; struct Edge{
int to, nxt;
}edge[mx*mx];
int head[mx], iE;
void addEdge(int u, int v){
edge[iE].to = v; edge[iE].nxt = head[u];
head[u] = iE++;
} struct Point{
ll x, y, r;
}data[mx];
bool cmp(int i, int j){
ll oo, rr;
oo = (data[i].x - data[j].x)*(data[i].x - data[j].x) + (data[i].y - data[j].y)*(data[i].y - data[j].y);
rr = data[i].r*data[i].r;
return oo <= rr;
} int stack[mx], inUS[mx], iS, ID[mx], fID[mx], iF, size[mx];
void Tarjan(int now){
fID[now] = ++iF;
stack[++iS] = now; inUS[now] = ;
int u, v, i = iS, fIDold = fID[now];
for (u = head[now]; ~u; u = edge[u].nxt){
v = edge[u].to;
++size[ID[v]];
if (inUS[v] == ) Tarjan(v);
if (~inUS[v]) fID[now] = std::min(fID[v], fID[now]);
}
if (fID[now] == fIDold){
while (iS >= i){
ID[stack[iS]] = now; inUS[stack[iS]] = -;
c[now] = std::min(c[stack[iS]], c[now]);
--iS;
}
}
} void read(){
scanf("%d", &n);
int i, j;
for (i = ; i < n; ++i){
scanf("%I64d%I64d%I64d%d", &data[i].x, &data[i].y, &data[i].r, &c[i]);
head[i] = -; ID[i] = i; inUS[i] = ;
}
iE = ;
for (i = ; i < n; ++i){
for (j = i + ; j < n; ++j){
if (cmp(i, j)) addEdge(i, j);
if (cmp(j, i)) addEdge(j, i);
}
} iS = iF = ;
for (i = ; i < n; ++i){
if (inUS[i] == ){ Tarjan(i); size[ID[i]] = ; }
}
} int sum(){
int i, opt = ;
for (i = ; i < n; ++i){
if (size[i] == ) opt += c[ID[i]];
}
return opt;
} int main(){
int t, it, i;
for (it = scanf("%d", &t); t; --t, ++it){
read();
printf("Case #%d: %d\n", it, sum());
}
return ;
}

HDU 5934 Bomb(炸弹)的更多相关文章

  1. HDU 5934 Bomb 【图论缩点】(2016年中国大学生程序设计竞赛(杭州))

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  2. hdu 5934 Bomb

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

  3. HDU 5934 Bomb(tarjan/SCC缩点)题解

    思路:建一个有向图,指向能引爆对象,把强连通分量缩成一点,只要点燃图中入度为0的点即可.因为入度为0没人能引爆,不为0可以由别人引爆. 思路很简单,但是早上写的一直错,改了半天了,推倒重来才过了... ...

  4. hdu 3555 Bomb 炸弹(数位DP,入门)

    题意: 给一个数字n,求从1~n中有多少个数是含有49的,比如49,149,1490等都是含49的. 思路: 2^64也顶多是十进制的20多位,那么按十进制位来分析更简单.如果能计算k位十进制数中分别 ...

  5. 【(最小权点基)tarjan强连通分量缩点+tarjan模板】HDU 5934 Bomb

    [AC] #include<bits/stdc++.h> using namespace std; typedef long long ll; int n; ; ; const int i ...

  6. 数位DP入门之hdu 3555 Bomb

    hdu 3555 Bomb 题意: 在1~N(1<=N<=2^63-1)范围内找出含有 ‘49’的数的个数: 与hdu 2089 不要62的区别:2089是找不不含 '4'和 '62'的区 ...

  7. HDU 3622 Bomb Game(2-sat)

    HDU 3622 Bomb Game 题目链接 题意:求一个最大半径,使得每一个二元组的点任选一个,能够得到全部圆两两不相交 思路:显然的二分半径,然后2-sat去判定就可以 代码: #include ...

  8. HDU 5934:Bomb(强连通缩点)

    http://acm.hdu.edu.cn/showproblem.php?pid=5934 题意:有N个炸弹,每个炸弹有一个坐标,一个爆炸范围和一个爆炸花费,如果一个炸弹的爆炸范围内有另外的炸弹,那 ...

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

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

随机推荐

  1. GPS部标平台的架构设计(三) 基于struts+spring+hibernate+ibatis+quartz+mina框架开发GPS平台

    注意,此版本是2014年研发的基于Spring2.5和Struts2的版本,此版本的源码仍然销售,但已不再提供源码升级的服务,因为目前我们开发的主流新版本是2015-2016年近一年推出的基于spri ...

  2. JAVA NIO系列(二) Channel解读

    Channel就是一个通道,用于传输数据,两端分别是缓冲区和实体(文件或者套接字),通道的特点(也是NIO的特点):通道中的数据总是要先读到一个缓冲区,或者总是要从一个缓冲区中读入. Channel的 ...

  3. js的一些实用的小技巧

    1.移动端自适应: 移动端的编写首先需要在header写入以下内容来表示页面是以不缩放的形式展示的: <meta name="viewport" content=" ...

  4. linux-----------shell的基础命令

    shell中截取字符串的方法有很多中, ${expression}一共有9种使用方法. ${parameter:-word} ${parameter:=word} ${parameter:?word} ...

  5. HUD 5050 Divided Land

    http://acm.hdu.edu.cn/showproblem.php?pid=5050 题目大意: 给定一个矩形的长和宽,把这个矩形分成若干相等的正方形,没有剩余.求正方形的边长最长是多少. 解 ...

  6. poj 1266 Cover an Arc.

    http://poj.org/problem?id=1266 Cover an Arc. Time Limit: 1000MS   Memory Limit: 10000K Total Submiss ...

  7. com.caucho.hessian.io.HessianProtocolException: is unknown code 解决方案

    问题: Cannot access Hessian remote service at [http://....../remote/syllabusService]; nested exception ...

  8. 【原创】如何在Android Studio下调试原生安卓Framework层面的源代码

    1. Open Existing Android Studio Project. 2. 打开后, Projects -> Android 里面是空的. 这时候,需要选到 Projects-> ...

  9. Foundation框架

    1.框架是由许多类.方法.函数.文档按照一定的逻辑组织起来的集合,以便使研发程序变的更容易 清除缓存,删除这个文件夹下的所有文件/Users/fanyafang/Library/Developer/X ...

  10. python 图片爬虫

    #!/usr/bin/env python #coding:utf-8 import urllib import re def GetHtml(url): """获取HT ...