怎么简单的题目,比赛时看都没看。。。。。不知道当时在干什么。。。。
用SublimeText敲代码的手感就是好

Problem 1546 - J - Maze
Time Limit: 1000MS   Memory Limit: 65536KB   
Total Submit: 68  Accepted: 8  Special Judge: No
Description

Get out from the maze!

He looks around, finding that the maze has only one exit but it has been locked. He has not enough energy to break the door and he must move out to find extra bonuses of energy hidden in the maze. He can move toward 4 directions: left, right, up, and down, which will take 1 second in a single move.

Unfortunately, there is an evil machine which will detect whether he is still there or not every L seconds in the initial place where he is located. And if he is out of the maze, the machine will surely be out of service.

Right after he is in the exit grid, he will be considered to be outside the maze.

Input
The input consists of one or more test cases.

First line of each test case contains 5 integers W(1<=W<=50), H(1<=H<=50), L(1<=L<=1,000,000), M(1<=M<=10), and S(0<=S<=10,000,000), indicating:
W: the width of the maze.
H: the height of the maze.
L: time of the round of the machine.
M: the number of the bonuses of energy.
S: energy needed to break the lock.

The next line contains M integers indicating the list of the energy-bonus.

Then there comes the map of the maze:
#: wall
.: empty place
$: initial position
<: exit grid
@: energy bonuses

Energy bonuses are ordered from the top to bottom, left to the right.

Output
For each test case, output “YES” or “NO”
Sample Input
3
4 4 2 2 200
100 200
####
#$@#
#@<#
####

4 4 1 2 300
100 200
####
#$@#
#@<#
####

12 5 13 2 400
100 200
############
#@.........#
#.########.#
#$...@....<#
############

Sample Output
YES
NO
NO
Hint
Source
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>using namespace std;const int INF=0x3f3f3f3f;
const int dir_x[4]={-1,1,0,0};
const int dir_y[4]={0,0,-1,1};typedef pair<int,int> pII;char maze[60][60];
int w,h,l,m,s,egy[20],EG[60][60],step[60][60];
int qi[60][60],zhong[60][60];
vector<pII> egpoint;void init()
{egpoint.clear();memset(maze,0,sizeof(maze));memset(egy,0,sizeof(egy));memset(EG,0,sizeof(EG));memset(step,0,sizeof(step));memset(qi,63,sizeof(qi));memset(zhong,63,sizeof(zhong));
}int main()
{int T_T;scanf("%d",&T_T);
while(T_T--)
{int sum=0;init();scanf("%d%d%d%d%d",&w,&h,&l,&m,&s);    for(int i=0;i<m;i++) scanf("%d",egy+i),sum+=egy[i];for(int i=0;i<h;i++) scanf("%s",maze[i]); //for(int i=0;i<h;i++) cout<<maze[i]<<endl;if(sum<s){puts("NO"); continue;///根本没有足够的能量}pII IP,EXIT;int cur=0;for(int i=0;i<h;i++){for(int j=0;j<w;j++){if(maze[i][j]=='$'){IP=make_pair(i,j);}else if(maze[i][j]=='<'){EXIT=make_pair(i,j);}else if(maze[i][j]=='@'){EG[i][j]=egy[cur++];egpoint.push_back(make_pair(i,j));}}}queue<pII> q;q.push(IP);qi[IP.first][IP.second]=0;while(!q.empty())//从起点到各个点的距离{pII u=q.front(),v; q.pop();for(int i=0;i<4;i++){v.first=u.first+dir_x[i];v.second=u.second+dir_y[i];if(maze[v.first][v.second]=='#'||qi[v.first][v.second]!=INF) continue;qi[v.first][v.second]=qi[u.first][u.second]+1;q.push(v);}}if(qi[EXIT.first][EXIT.second]>l){puts("NO"); continue;  ///即使不要能量也跑不出去}while(!q.empty()) q.pop();q.push(EXIT);zhong[EXIT.first][EXIT.second]=0;while(!q.empty())///各个点到出口的距离{pII u=q.front(),v; q.pop();for(int i=0;i<4;i++){v.first=u.first+dir_x[i];v.second=u.second+dir_y[i];if(maze[v.first][v.second]=='#'||zhong[v.first][v.second]!=INF) continue;zhong[v.first][v.second]=zhong[u.first][u.second]+1;q.push(v);}}int CAN=0;for(int i=0,sz=egpoint.size();i<sz;i++)    {int X=egpoint[i].first;int Y=egpoint[i].second;if(qi[X][Y]*2<=l||zhong[X][Y]*2<=l||qi[X][Y]+zhong[X][Y]<=l) CAN+=EG[X][Y];}if(CAN>=m) puts("YES");else puts("NO");
}return 0;
}

WOJ 1546 Maze相关推荐

  1. [A Dangerous Maze LightOJ - 1027 ][概率题]

    A Dangerous Maze LightOJ - 1027 题目大意:就是你有nnn个门每次你都会随机选一个门,这个门对应得数值如果是负的那么你将会在aia_iai​的时间后回到原来位置,如果是正 ...

  2. (POJ 3026) Borg Maze 最小生成树+bfs

    题目链接:http://poj.org/problem?id=3026. DescriptionThe Borg is an immensely powerful race of enhanced h ...

  3. 【POJ 3026】Borg Maze

    [POJ 3026]Borg Maze 一个考察队搜索alien 这个考察队能够无限切割 问搜索到全部alien所须要的总步数 即求一个无向图 包括全部的点而且总权值最小(最小生成树 BFS+最小生成 ...

  4. C++rat maze老鼠迷宫算法(附完整源码)

    rat maze老鼠迷宫的算法 rat maze老鼠迷宫的算法的完整源码(定义,实现,main函数测试) rat maze老鼠迷宫的算法的完整源码(定义,实现,main函数测试) #include & ...

  5. [Mummy Maze] 宽度优先搜索

    有个小游戏ms很有意思 叫Mummy Maze 这边有一个下载地址 有兴趣的可以试试 http://www.jz5u.com/Soft/games/chess/20301.html 我也在玩 不过我写 ...

  6. Solve The Maze CodeForces - 1365D(贪心+dfs)

    Vivek has encountered a problem. He has a maze that can be represented as an n×m grid. Each of the g ...

  7. NEKO's Maze Game(思维)

    3R2 as DJ Mashiro - Happiness Breeze Ice - DJ Mashiro is dead or alive NEKO#ΦωΦ has just got a new m ...

  8. HDU 4035 Maze

    Maze http://acm.hdu.edu.cn/showproblem.php?pid=4035 分析: 在树上走来走去,然后在一个点可以k的概率回到1,可以e的概率走出去,可以1-k-e的概率 ...

  9. LightOJ - 1027 A Dangerous Maze —— 期望

    题目链接:https://vjudge.net/problem/LightOJ-1027 1027 - A Dangerous Maze     PDF (English) Statistics Fo ...

最新文章

  1. linux下解压缩文件中文乱码问题的解决
  2. 在悬崖下得到鸿蒙塔,第一次夜宿在悬崖峭壁上:垂直高度356米,峡谷深渊就在边上...
  3. phpstudy php日志,phpstudy开启网站Apache日志并且按照日期划分创建
  4. wxWidgets:wxLayoutAlgorithm类用法
  5. c语言 个位,如何才能给C语言增加几个位操作函数
  6. GC 年轻代 老年代 持久代
  7. cctype 定义的函数 (记忆)
  8. 动手制作Dos、WinPE、Slax Linux|winpe+dos+Mini Linux U盘启动盘
  9. Android初学第32天
  10. Java全栈程序员之03:Ubuntu下安装idea
  11. React Component里的状态机Pattern
  12. 无线摄像头接有线如何改协议_WiFi中继器——让无线传输更简单
  13. Shell脚本之免交互操作
  14. oracle11g64位怎么用sql,plsql32 位连接oracle11g64位方法
  15. 算法练习-珠心算测验
  16. 关于microsoft html help workshop的一些草蛋问题
  17. html展开插件,分享10款功能强大的HTML5/CSS3应用插件
  18. python重装之前要卸载吗_关于fedroa下安全地卸载和重装python
  19. Bootstrap-表格合并单元格
  20. 课时31:永久储存:腌制一缸美味的泡菜

热门文章

  1. DVDRW光驱无法读DVD刻录盘
  2. 数学黑洞(一)令人拍案叫绝的卡布列克常数
  3. 【.Net码农】【淘宝API】淘宝API开发
  4. php 替换表情符号,javascript字符串替换文本到php页面中的表情符号
  5. 黑马C++之 数据类型——整形、实型、字符型、转义字符、字符串类型、布尔类型
  6. 网络层(王道视频笔记)
  7. 二叉树的先序、中序、后序、层序遍历方式详解,由遍历序列构造二叉树过程详解以及C++代码详细实现
  8. 2019年04月01日_拔剑-浆糊的传说_新浪博客
  9. mysql之把查询的结果保存到新表
  10. JPA 中 findById()踩过的坑