麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

POJ 1010

2019-11-14 09:09:11
字體:
來源:轉載
供稿:網友

PRoblem Description

The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone was a trap, and he tried desperately to get out of this maze.

The maze was a rectangle with sizes N by M. There was a door in the maze. At the beginning, the door was closed and it would open at the T-th second for a short period of time (less than 1 second). Therefore the doggie had to arrive at the door on exactly the T-th second. In every second, he could move one block to one of the upper, lower, left and right neighboring blocks. Once he entered a block, the ground of this block would start to sink and disappear in the next second. He could not stay at one block for more than one second, nor could he move into a visited block. Can the poor doggie survive? Please help him.

Input

The input consists of multiple test cases. The first line of each test case contains three integers N, M, and T (1 < N, M < 7; 0 < T < 50), which denote the sizes of the maze and the time at which the door will open, respectively. The next N lines give the maze layout, with each line containing M characters. A character is one of the following:

‘X’: a block of wall, which the doggie cannot enter; ‘S’: the start point of the doggie; ‘D’: the Door; or ‘.’: an empty block.

The input is terminated with three 0’s. This test case is not to be processed.

Output

For each test case, print in one line “YES” if the doggie can survive, or “NO” otherwise.

Note:

This question belongs to dfs family.Something we should notice is the steps mentioned in the question.And I learn a mean of cutting-edges is to calculate the steps left and x-axis and y- axis length form current point to final point,if they are both even or odd ,the path is available.If you want to testify it ,you can simply draw a map and try. and I find a good function model for dfs

void DFS( argument ){ // recursion boundary // check if the argument has reached the ans // some action // keep recursion}#include <bits/stdc++.h>using namespace std;int dir[4][2]={ {0,1} , {1,0} , {-1,0} , {0,-1} };char m[10][10];int vis[10][10];int N,M,T,tx,ty;int flag=0;bool check(int a,int b){ if(a<0||a>=N||b<0||b>=M) { return false; } else { return true; }}void dfs(int x,int y,int d){ if(check(x,y)==false) return; vis[x][y]=1; if(x==tx && y==ty && d==T) { flag=1; return;} if(((T-d)%2)!=((abs(x-tx)+abs(y-ty))%2)) return; for(int i=0;i<4;i++) { if(!vis[x+dir[i][1]][y+dir[i][0]]&&!flag) { dfs(x+dir[i][1],y+dir[i][0],d+1); vis[x+dir[i][1]][y+dir[i][0]]=0; } } }int main(){ while(cin>>N>>M>>T) { memset(m,0,sizeof(m)); memset(vis,0,sizeof(vis)); int sx,sy; if(N==0&&M==0&&T==0) { break; } else { for(int i=0;i<N;i++) { scanf("%s",m[i]); } for(int i=0;i<N;i++) { for(int j=0;j<M;j++) { char t=m[i][j]; if(t=='X'||t=='x') { vis[i][j]=1; } else { if(t=='S'||t=='s') { sx=i; sy=j; } else if(t=='D'||t=='d') { tx=i; ty=j; } } } } } flag=0; dfs(sx,sy,0); if(flag==1) { cout<<"YES"<<endl; } else { cout<<"NO"<<endl; } } return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 在线播放免费视频 | 欧美日韩国产一区二区三区在线观看 | 哪里可以看免费的av | 麻豆视频在线观看免费网站 | 作爱在线观看 | 久久久久一区 | 久久黄色影院 | 国产精品性夜天天视频 | 在线观看免费视频麻豆 | 素人视频在线观看免费 | 国产日韩线路一线路二 | 成人午夜影院 | 色猫av| 欧美激情在线播放 | xxx18hd18hd日本 | 羞羞的动漫在线观看 | 免费国产在线观看 | 72pao成人国产永久免费视频 | 亚洲欧美天堂 | 嫩草影院在线观看网站成人 | 国产成人精品区一区二区不卡 | 黄污污网站 | 色猫av| 欧美成人免费看 | 精品国产一区二区在线 | 精品国产精品久久 | 97超碰资源站 | 美女毛片在线观看 | 91精品福利视频 | 久色精品视频 | 91精品国产91久久久 | 国产一国产一级毛片视频 | 欧美成人黄色小视频 | 成人国产精品一区 | 91麻豆精品国产91久久久无需广告 | 久草在线新时代视觉 | 91精品国产777在线观看 | 欧美一级成人 | 电影av在线 | xxxxhdvideosex| 国产一区国产二区在线观看 |