hdu1072 Nightmare
来源:互联网 发布:华南理工网络教育文凭 编辑:程序博客网 时间:2024/05/21 08:36
Nightmare
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 91 Accepted Submission(s) : 59
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Given the layout of the labyrinth and Ignatius' start position, please tell Ignatius whether he could get out of the labyrinth, if he could, output the minimum time that he has to use to find the exit of the labyrinth, else output -1.
Here are some rules:
1. We can assume the labyrinth is a 2 array.
2. Each minute, Ignatius could only get to one of the nearest area, and he should not walk out of the border, of course he could not walk on a wall, too.
3. If Ignatius get to the exit when the exploding time turns to 0, he can't get out of the labyrinth.
4. If Ignatius get to the area which contains Bomb-Rest-Equipment when the exploding time turns to 0, he can't use the equipment to reset the bomb.
5. A Bomb-Reset-Equipment can be used as many times as you wish, if it is needed, Ignatius can get to any areas in the labyrinth as many times as you wish.
6. The time to reset the exploding time can be ignore, in other words, if Ignatius get to an area which contain Bomb-Rest-Equipment, and the exploding time is larger than 0, the exploding time would be reset to 6.
Input
Each test case starts with two integers N and M(1<=N,Mm=8) which indicate the size of the labyrinth. Then N lines follow, each line contains M integers. The array indicates the layout of the labyrinth.
There are five integers which indicate the different type of area in the labyrinth:
0: The area is a wall, Ignatius should not walk on it.
1: The area contains nothing, Ignatius can walk on it.
2: Ignatius' start position, Ignatius starts his escape from this position.
3: The exit of the labyrinth, Ignatius' target position.
4: The area contains a Bomb-Reset-Equipment, Ignatius can delay the exploding time by walking to these areas.
Output
Sample Input
33 32 1 11 1 01 1 34 82 1 1 0 1 1 1 01 0 4 1 1 0 4 11 0 0 0 0 0 0 11 1 1 4 1 1 1 35 81 2 1 1 1 1 1 4 1 0 0 0 1 0 0 1 1 4 1 0 1 1 0 1 1 0 0 0 0 3 0 1 1 1 4 1 1 1 1 1
Sample Output
4-113
初始时间为6,地图中会有时间重置器,注意只要在搜索的过程中碰到时间重置器后将其变为强就好了
#include<iostream>#include<cstring>#include<queue>using namespace std;int ma[10][10];int xx,yy;int x1[4]={1,0,0,-1};int y1[4]={0,1,-1,0};struct point{ int x; int y; int t; int bs;};bool check(int x,int y){ if(ma[x][y]==0||x<1||x>xx||y<1||y>yy) return 0; return 1;}int bfs(int xs,int ys){ queue<point> lss; point tt; tt.x=xs; tt.y=ys; tt.t=6; tt.bs=0; lss.push(tt); while(!lss.empty()){ tt=lss.front(); lss.pop(); if(ma[tt.x][tt.y]==3&&tt.t>0) { return tt.bs; } if(ma[tt.x][tt.y]==4&&tt.t>0) { tt.t=6; ma[tt.x][tt.y]=0; } if(tt.t==1)continue; for(int i=0;i<4;i++){ int xxx=tt.x+x1[i]; int yyy=tt.y+y1[i]; if(check(xxx,yyy)) {point hh; hh.x=xxx; hh.y=yyy; hh.t=tt.t-1; hh.bs=tt.bs+1; lss.push(hh); } } } return -1;}int main(){ int n; scanf("%d",&n); while(n--){ scanf("%d%d",&xx,&yy); int i,j; int X,Y; for(i=1;i<=xx;i++) { for(j=1;j<=yy;j++) { scanf("%d",&ma[i][j]); if(ma[i][j]==2) { X=i; Y=j; } } } int ans=bfs(X,Y); cout<<ans<<endl; }return 0;}
- HDU1072 Nightmare
- hdu1072 Nightmare
- hdu1072-Nightmare
- HDU1072 nightmare
- hdu1072 nightmare
- Hdu1072 Nightmare
- HDU1072:Nightmare
- Nightmare hdu1072
- HDU1072-Nightmare
- HDU1072 Nightmare
- hdu1072 Nightmare
- hdu1072 Nightmare
- hdu1072 Nightmare (BFS)
- hdu1072 Nightmare (BFS)
- HDU1072 Nightmare 【BFS】
- hdu1072 Nightmare 广搜
- hdu1072 Nightmare(BFS)
- hdu1072 Nightmare(bfs)
- iOS MediaPlayer(视频播放器) 笔记
- [7.11] 纪中C组
- 多线程编程10例问题(5)
- E
- MFC中OnMouseWheel不触发的原因之一
- hdu1072 Nightmare
- FPGA基础设计(一):VGA显示方法(文字、图形、波形)的全方面解析
- Linux JDK环境变量配置
- 微信公众号自定义菜单post请求错误解决办法
- hdu1078 FatMouse and Cheese
- 并发服务器
- samba配置
- 数据库读写分离
- hdu 1180 诡异的楼梯