Maze


Time Limit: 2 Seconds      Memory Limit: 65536 KB

Celica is a brave person and believer of a God in the bright side. He always fights against the monsters that endanger humans. One day, he is asked to go through a maze to do a important task.

The maze is a rectangle of n*m, and Celica is at (x1, y1) at the beginning while he needs to go to (x2, y2). And Celica has a Mobility of l. When he moves a step the movility will decreased by 1. If his mobility equals to 0, he can't move anymore in this turn. And no matter how much mobility Celica uses in one turn, his movility will become l again in the next turn. And a step means move from one lattice to another lattice that has an adjacent edge.

However, due to the world's rule and the power of magic, there is something called Dominance in the maze. Some lattices may be dominated by some monsters and if Celica goes into these lattices, his mobility will be reduced to 0 at once by the monster's magic power. And monsters have strong "Domain awareness" so one lattice won't be dominated by more than one monster.

But luckily, Celica gets a strong power from his God so that he can kill this monsters easily. If Celica goes into a lattice which a monster stands on, he can kill the monster without anytime. If a monsters is killed, the lattices it dominates will no longer be dominated by anyone(or we can say they are dominated by Celica) and these lattices will obey the rule of mobility that normal lattices obey.

As for the task is so important that Celica wants to uses the least turn to go to (x2, y2). Please find out the answer.

PS1: It doesn't matter if Celica doesn't kill all the monsters in the
maze because he can do it after the task and a monster may appear at a lattice
that is not dominated by it, even a lattice that is not dominated by any
monsters.

PS2: We define (1,1) as the top left corner. And monsters won't
move.

PS3: No matter which lattice Celia gets in, the change of mobility
happens first.

PS4: We promise that there is no two monsters have same
position and no monster will appear at the start point of Celica.

Input

The first contains three integers, n, m,
l.(1≤n, m≤50, 1≤l≤10)

Then
there follows n lines and each line contains m integers.
The j-th integer p in the line i describe the
lattice in the i line and j row. If p euqals to
-1, it means you can't get into it. If p euqals to 0, it means the
lattice is not dominated by any monster. If p is larger than 0, it
means it is dominated by the p-th monster.

And then in the
n+2 line, there is an integer k(0≤k≤5) which
means the number of monster.

Then there follows k lines. The
i-th line has two integers mean the position of the i-th
monster.

At last, in the n+k+3 lines, there is four
integers x1, y1, x2, y2.

Output

If Celica can't get to the (x2, y2), output "We need
God's help!", or output the least turn Celica needs.

Sample Input

5 5 4
2 2 2 1 0
-1 2 2 -1 1
2 2 2 1 1
1 1 1 1 0
1 2 2 -1 0
2
4 2
1 1
5 1 1 5
5 5 4
1 1 1 1 1
1 2 2 -1 -1
2 2 -1 2 2
-1 -1 2 2 2
2 2 2 2 2
2
2 2
1 2
1 1 5 5

Sample Output

4
We need God's help!

Hit

In the first case, Celica goes to (4,1) in turn 1. Then he goes to (4,2) in turn 2. After he gets (4,2), kill the monster 1. He goes through (4,3)->(4,4)>(3,4)->(3,5) in turn 3. At last he goes (2,5)->(1,5) in turn 4.


Author: ZHANG, Ruijie


这道题感觉特别恶心,题超长,翻译看哭我。。。而且限制条件有点烦,注意看懂题意才能写。。

题意:

题目大意:打怪兽。给一个n*m的地图,其中1~5表示该位置被第i个怪兽管理着,0表示空地可以走,-1表示这个位置不可以走。

再输入一个k,接下去k行怪兽所在的坐标。

最后一行就是Celica的起点和终点,问最少需要多少回合才能走到终点。

特别注意:

1、每一个回合开始,Celica的初始体力值为L,每移动一次,体力值减1,当体力值==0时,开始下一回合。

2、只要进入怪兽所管理的位置,体力值就瞬间变为0。

3、如果进入到怪兽所在的位置,就要将怪兽打死,体力值变为0,。与此同时,地图上怪兽的位置和怪兽所控制的位置全部变为0(无障碍空地)。

4、起点没有怪,但可能被某一个怪兽控制。

5、如果起点和终点重合,直接输出0。即回合数为0.

6、怪兽不一定在他控制的位置,被一号怪兽控制的区域也可以是2号怪兽。

7、复活过得地方不会在死一次了,并且起始点就算是复活地。

8、在到达终点的时候,体力值刚好变为0的话,不会再另外算一个回合,需要特殊判断。

9、如果不能到达终点的话,记得输出We need God's help!

附上代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
int map[][],m,n,w;
int f[][]= {,,,-,,,-,};
int k,a[],b[];
int x1,y1,x2,y2;
int vis[][][]; //使用状态压缩,记录怪物被杀的情况 struct node
{
int x,y; //当前的坐标
int step; //当前的体力
int t; //回合数
int flag; //标记怪物的存活情况
friend bool operator < (node n1,node n2) //优先队列,回合少的优先,回合相等,剩余体力多的优先
{
if(n1.t!=n2.t)
return n1.t>n2.t;
return n1.step<n2.step;
}
} s1,s2; void BFS()
{
priority_queue<node> q;
while(!q.empty())
q.pop();
memset(vis,,sizeof(vis));
s1.x=x1;
s1.y=y1;
s1.step=w; //初始体力为w
s1.t=;
s1.flag=; //初始为0,表示怪物全部存活
vis[x1][y1][]=; //记录这种状态已出现过
q.push(s1);
while(!q.empty())
{
s1=q.top();
q.pop();
if(s1.x==x2&&s1.y==y2) //走到了终点
{
if(s1.step==w) //如果此时体力为满,则说明上一个回合体力为0时,刚好到达终点,因此当前回合数减一
printf("%d\n",s1.t-);
else
printf("%d\n",s1.t);
return;
}
for(int i=; i<; i++)
{
s2.x=s1.x+f[i][];
s2.y=s1.y+f[i][];
s2.flag=s1.flag;
s2.t=s1.t;
if(s2.x>=&&s2.x<=n&&s2.y>=&&s2.y<=m&&map[s2.x][s2.y]!=-&&!vis[s2.x][s2.y][s2.flag])
//不能超出地图范围,不能是墙,这种状态不能出现过
{
vis[s2.x][s2.y][s2.flag]=;
if(map[s2.x][s2.y]==||(s2.flag&(<<(map[s2.x][s2.y])))!=) //判断怪物是否被打死
s2.step=s1.step-; //打死了或没怪物则体力减一
else
s2.step=; //否则体力清零
for(int j=; j<=k; j++)
if(s2.x==a[j]&&s2.y==b[j]) //如果走到有怪物的地方,杀死怪物,用flag记录
{
s2.flag=s2.flag|(<<j);
}
if(s2.step==) //如果体力为0,则开启下一回合,并且体力恢复到w
{
s2.t++;
s2.step=w;
}
q.push(s2); // 入队
} }
}
printf("We need God's help!\n"); //如果搜不到,则输出这个
} int main()
{
int i,j;
while(~scanf("%d%d%d",&n,&m,&w))
{
for(i=; i<=n; i++)
for(j=; j<=m; j++)
scanf("%d",&map[i][j]);
scanf("%d",&k); //输入怪物个数
for(i=; i<=k; i++)
scanf("%d%d",&a[i],&b[i]); //记录每个怪物的位置
scanf("%d%d%d%d",&x1,&y1,&x2,&y2); //输入起点和终点
if(x1==x2&&y1==y2) //若起点就是终点,则回合数为0
{
printf("0\n");
continue;
}
BFS();
}
return ;
}

zoj 3652 Maze的更多相关文章

  1. ZOJ 3652 Maze 模拟,bfs,读题 难度:2

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4842 要注意题目中两点: 1.在踏入妖怪控制的区域那一刹那,先减行动力,然后才 ...

  2. ZOJ 3992 One-Dimensional Maze(思维题)

    L - One-Dimensional Maze Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & % ...

  3. POJ 3652 &amp; ZOJ 2934 &amp; HDU 2721 Persistent Bits(数学 元)

    主题链接: PKU:http://poj.org/problem?id=3652 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do? probl ...

  4. poj 2096 Collecting Bugs && ZOJ 3329 One Person Game && hdu 4035 Maze——期望DP

    poj 2096 题目:http://poj.org/problem?id=2096 f[ i ][ j ] 表示收集了 i 个 n 的那个. j 个 s 的那个的期望步数. #include< ...

  5. ZOJ - 3992 - One-Dimensional Maze (思维)

    题意: 一条长度为n的直线,你一开始在位置m上 其中每个整点都有一个字符'L'或'R',如果是'L'那么你必须往左走一步,否则往右走一步 如果你到达位置1或位置n你任务就完成了 不过有可能你永远到不了 ...

  6. BFS+模拟 ZOJ 3865 Superbot

    题目传送门 /* BFS+模拟:dp[i][j][p] 表示走到i,j,方向为p的步数为多少: BFS分4种情况入队,最后在终点4个方向寻找最小值:) */ #include <cstdio&g ...

  7. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  8. POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索)

    POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索) Description You ar ...

  9. zoj 2081 BFS 延迟标记 读入问题

    Mission Impossible Time Limit: 2 Seconds                                     Memory Limit: 65536 KB  ...

随机推荐

  1. Laravel 精选资源大全

    原文链接  必备品 文档:Documentation API:API Reference 视频:Laracasts 新闻:Laravel News 中文文档 Laravel学院– Laravel 5. ...

  2. 机器学习中的那些树——决策树(三、CART 树)

    前言 距上篇文章已经过了9个月 orz..趁着期末复习,把博客补一补.. 在前面的文章中介绍了决策树的 ID3,C4.5 算法.我们知道了 ID3 算法是基于各节点的信息增益的大小 \(\operat ...

  3. 备考2019年6月份PMP考试-分享一些考试笔记(二)

    最新比较经典的100道试题,有备考的小伙伴可以练练手,文章末尾附答案. 1     一个项目经理在运作一个数据中心安装项目.他发现相关方很恼火,因为他超出了预算,原因是人员费用要高于原先的计划.另外项 ...

  4. Liferay 7 OSGi第三方jar包依赖问题

    发现遇到这个问题的人挺多的,现在跟新一下好好写. 在开发Liferay的时候,我们常常会遇到Unresolved requirement: Import-Package: {package name} ...

  5. linux awk命令详解,使用system来内嵌系统命令, awk合并两列

    linux awk命令详解 简介 awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大.简单来说awk就是把文件逐行的读入,以空格为默认分 ...

  6. firefox扩展开发(二):用XUL创建窗口控件

    firefox扩展开发(二):用XUL创建窗口控件 2008-06-11 16:57 1.创建一个简单的窗口 <?xml version="1.0"?> <?xm ...

  7. 2019.9.10附加题while练习

    题目:企业发放的奖金根据利润提成.利润(I)低于或等于10万元时,奖金可提10%:利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.5%:20万到40万之 ...

  8. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十七章:拾取

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十七章:拾取 代码工程地址: https://github.com/ ...

  9. kubernetes1.3:操作Docker

    Kubernetes对Docker的管理是通过一个第三方组件实现的.在Kubernetes1.2中这个第三方组件就是go-dockerclient,这是一个GO语言写的docker客户端,支持Dock ...

  10. POJ-1125_Stockbroker Grapevine

    Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Description Stockbrokers are known to ...