UVALive 5066 Fire Drill BFS+背包
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
Description
Joko is taking part in a fire drill which is held by the Jakarta Fire Department to recruit new firemen. The drill is about rescuing volunteers (who act as unconscious people) trapped in a building in a limited time. The building has several floors, and the volunteers are scattered throughout the building. Each volunteer has points assigned to her. The fireman candidate should rescue volunteers through carrying them to the exit. The candidate will earn the assigned points for each volunteer he rescued.
Each floor of a building can be seen as a grid of cells. Each cell can be an obstacle, an empty space, a stair or an entry/exit point.
A candidate starts at the entry point which exists only at one single cell of the first floor of the building. The candidate can move to any adjacent non-obstacle cells (north, south, west or east) or climb up or down a stair in 1 second. The movement slows down to 2 seconds when the candidate carries a volunteer. When a candidate finds a volunteer, he may decide to rescue her or not, but if he decides to rescue her, he has to carry her back to the exit without stopping. He can only carry at most one volunteer at a time.
Joko has the floor plan of the test building. Help him plan his moves, so he can get the highest possible score.
Input
The first line of input contains an integer T(T
100) denoting the number of case. Each case has five integers L(1
L
10), H(1
H
100), W(1
W
100), N(1
N
100) and S(1
S
10, 000) denoting the number of floors, height and weight of each floor, the number of unconscious people, and the given time respectively.
The next L blocks describe the map of each floor from the 1st floor to the L-th floor respectively. Each floor consists of H lines each contains W characters. Characters that may appear in each floor are:
- ``S" : The starting point, also serves as the exit point. There will be only one starting/exit point and it will appear in the first floor.
- ``X" : Obstacle, cell that cannot be visited (wall, fire, etc.).
- ``U" : Stair that connect to the upper floor. There will be a ``D" character at the same place in the upper level. This character will not appear in the highest level of the building.
- ``D" : Stair that connect to the lower floor. There will be a ``U" character at the same place in the lower level. This character will not appear in the lowest level of the building.
- ``." : Empty space, cell that can be visited.
The next N lines each contains four integers fi(1
fi
L), ri(1
ri
H), ci(1
ci
W), pi(1
pi
1, 000)
denoting the location of each volunteer (floor, row, column) and the
point assigned to this volunteer respectively. You can assume that each
volunteer will be located in empty space and no two volunteer occupy the
same location.
Output
For each case, output in a line a single integer the highest point that
he can earn by rescuing unconscious people within the given time.
Sample Input
2
3 3 5 3 55
XXXXX
X..UX
XSXXX
XXXXX
XU.DX
XXXXX
XXXXX
XD..X
XXXXX
1 2 3 10
3 2 3 50
3 2 4 60
2 2 6 4 27
......
S..U..
......
...D..
1 2 3 20
1 2 5 50
1 2 6 50
2 1 1 90
Sample Output
110
100
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std; struct node
{
int x,y,z,t;
};
const int d[][]= {{,,},{,,},{,-,},{,,-}};
char ss[][][];
int pp[][][];
int h,w,L;
int S,V[],p[],f[];
bool zg[][][];
char sss[];
node R[];
int ggg,gg;
bool check(int z,int x,int y)
{
if(x>-&&y>-&&z>-&&z<h&&x<w&&y<L)
return ;
return ;
}
void bfs (int xx,int yy,int zz,int tt)
{
int i;
int x3,y3,z3; if(ss[zz][xx][yy]=='P')
{
p[pp[zz][xx][yy]]=tt*;
}
if (ss[zz][xx][yy]=='U'&&zg[zz+][xx][yy]==)
{
zg[zz+][xx][yy]=;
R[ggg].x=xx;
R[ggg].y=yy;
R[ggg].z=zz+;
R[ggg++].t=tt+;
}
if (ss[zz][xx][yy]=='D'&&zg[zz-][xx][yy]==)
{
zg[zz-][xx][yy]=;
R[ggg].x=xx;
R[ggg].y=yy;
R[ggg].z=zz-;
R[ggg++].t=tt+;
}
for (i=;i<;i++)
{
x3=xx+d[i][];
y3=yy+d[i][];
z3=zz;
if (check(z3,x3,y3)&&ss[z3][x3][y3]!='X'&&zg[z3][x3][y3]==)
{
zg[z3][x3][y3]=;
R[ggg].x=x3;
R[ggg].y=y3;
R[ggg].z=z3;
R[ggg++].t=tt+;
}
}
++gg;
if (gg!=ggg) bfs(R[gg].x,R[gg].y,R[gg].z,R[gg].t);
} int main()
{
int T,N,x,y,z,i,j,t;
int ex,ey;
scanf("%d",&T);
while(T--)
{
ggg=;gg=-;
scanf("%d%d%d%d%d",&h,&w,&L,&N,&S);
for(i=;i<h;i++)
{
for(j=;j<w;j++)
{
scanf("%s",sss);
for(t=;t<L;t++)
{
zg[i][j][t]=;
ss[i][j][t]=sss[t];
if(sss[t]=='S')
{
ex=j,ey=t;
}
}
}
} for(int i=; i<N; i++)
{
scanf("%d%d%d%d",&z,&x,&y,&V[i]);
ss[z-][x-][y-]='P';
pp[z-][x-][y-]=i;
p[i]=S+;
}
zg[][ex][ey]=;
bfs(ex,ey,,);
//01背包
memset(f,,sizeof(f));
for(i=;i<N;i++)
{
for(j=S;j>=p[i];j--)
{
f[j]=max(f[j],f[j-p[i]]+V[i]);
}
}
printf("%d\n",f[S]);
}
return ;
}
UVALive 5066 Fire Drill BFS+背包的更多相关文章
- UVALive 5066 Fire Drill --BFS+DP
题意:有一个三维的地图,有n个人被困住,现在消防队员只能从1楼的一个入口进入,营救被困者,每一个被困者有一个价值,当消防队员找到一个被困者之后,他可以营救或者见死不救,如果救的话,他必须马上将其背到入 ...
- UVA 11624 - Fire! 图BFS
看题传送门 昨天晚上UVA上不去今天晚上才上得去,这是在维护么? 然后去看了JAVA,感觉还不错昂~ 晚上上去UVA后经常连接失败作死啊. 第一次做图的题~ 基本是照着抄的T T 不过搞懂了图的BFS ...
- UVa 11624 Fire!(BFS)
Fire! Time Limit: 5000MS Memory Limit: 262144KB 64bit IO Format: %lld & %llu Description Joe ...
- (简单) UVA 11624 Fire! ,BFS。
Description Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the ow ...
- (FZU 2150) Fire Game (bfs)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=2150 Problem Description Fat brother and Maze are playing ...
- FZU 2150 Fire Game (bfs+dfs)
Problem Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M board ...
- UVALive 4025 Color Squares(BFS)
题目链接:UVALive 4025 Color Squares 按题意要求放带有颜色的块,求达到w分的最少步数. //yy:哇,看别人存下整个棋盘的状态来做,我什么都不想说了,不知道下午自己写了些什么 ...
- UVA - 11624 Fire! 【BFS】
题意 有一个人 有一些火 人 在每一秒 可以向 上下左右的空地走 火每秒 也会向 上下左右的空地 蔓延 求 人能不能跑出来 如果能 求最小时间 思路 有一个 坑点 火是 可能有 多处 的 样例中 只有 ...
- UVA - 11624 Fire! 双向BFS追击问题
Fire! Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of ...
随机推荐
- USB设备被识别流程【转】
转自:http://blog.csdn.net/myarrow/article/details/8286876 USB模块包括usb core,host,hub,device驱动,其中hub会启动一个 ...
- MySQL增量备份与恢复实例【转】
小量的数据库可以每天进行完整备份,因为这也用不了多少时间,但当数据库很大时,就不太可能每天进行一次完整备份了,这时候就可以使用增量备份.增量备份的原理就是使用了mysql的binlog日志.本次操作的 ...
- MAVLink v1.0详解——结构
本文针对 MAVLink v1.0版本,协议版本:3. MAVLink是为微型飞行器MAV(Micro Air Vehicle)设计的(LGPL)开源的通讯协议.是无人飞行器和地面站(Ground C ...
- Nginx - buffer缓冲区部分
目录- 1. 前言- 2. 指令- 3. 原理及总结 1. 前言 关于缓冲,主要是合理设置缓冲区大小,尽量避免缓冲到硬盘 2. 指令 proxy_buffering 说明:proxy_bufferin ...
- python基础学习之路No.3 控制流if,while,for
在学习编程语言的过程中,有一个很重要的东西,它就是判断,也可以称为控制流. 一般有if.while.for三种 ⭐if语句 if语句可以有一个通俗的解释,如果.假如 如果条件1满足,则…… 如果条件2 ...
- supervisor管理uwsgi
1. 前言 传统的管理uwsgi服务: 1. 通过shell脚本来编写start restart stop函数来控制 2. 比较麻烦,有时候控制写的烂,还会出现意想不到的错误 supervisor进行 ...
- 20155309 《Java程序设计》实验三(Java面向对象程序设计)实验报告
一.实验内容及步骤 (一)编码标准 在IDEA中使用工具(Code->Reformate Code)把代码重新格式化. (二)在码云上把自己的学习搭档加入自己的项目中,确认搭档的项目加入自己后, ...
- linux nc命令使用详解(转)
linux nc命令使用详解 功能说明:功能强大的网络工具 语 法:nc [-hlnruz][-g<网关...>][-G<指向器数目>][-i<延迟秒数>][-o& ...
- ld 脚本浅析-LD手册粗糙翻译
本文乃转载, 我在其基础上做了少量修改. 原作者的E-mail是zhanglei@sict.ac.cn. 完成于2005.11.5-2005.11.8 0. Contents 1. 概论2. 基本概念 ...
- **后台怎么处理JSON数据中含有双引号?
http://bbs.csdn.net/topics/390578406?page=1 注意是后台,不是用js另外我这个json是直接取得别人的传过来的字符串,不是我自己拼写的,所以我自己不能做到转义 ...