HDU 1010 Tempter of The Bone
来源:互联网 发布:软件售后分那些 编辑:程序博客网 时间:2024/06/11 04:38
原题链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1010
题目大意:
略
思路:
时间刚好的时候才可以逃离
如果当前位置和终点的位置的最短距离大于剩余时间也不可以
如果当前位置和终点的位置的最短距离和剩余时间的奇偶性不同也不可以(一块地砖只能走一次)
代码如下:
#include <iostream>#include <cstdio>char maze[10][10]; //存放迷宫信息int check[10][10]; //标记数组。用于检测这个点是否走过int Maze_Long,Maze_Wide;int S_x,S_y;int D_x,D_y;bool Can;int Time;using namespace std;int fabs( int p ){ return p > 0? p : -p; }void Go( int start_x, int start_y ,int time ){ if( Can ) return; //到达判定 if( start_x == D_x && start_y == D_y && time == Time ) { Can = true; return; } //最短距离 int Short = fabs( start_x - D_x ) + fabs( start_y - D_y ); //剩余的最短距离和剩余时间的关系。 if( Short > Time - time || (Short + Time - time )%2 != 0 ) return; int Xz[4]={-1,0,1,0}; int Yz[4]={0,1,0,-1}; int k,new_x,new_y; for( k = 0; k < 4; k++ ) { new_x = start_x + Xz[k]; new_y = start_y + Yz[k]; //越界判定 if( new_x < 0 || new_x >= Maze_Wide || new_y < 0 || new_y >= Maze_Long) continue; if( maze[new_x][new_y] != 'X' && !check[new_x][new_y] ) { check[new_x][new_y] = 1; Go( new_x,new_y,time+1 ); check[new_x][new_y] = 0; } }}int main(){ while(1) { int time; int count; count = 0; cin>>Maze_Long>>Maze_Wide>>Time; if( Maze_Long == 0 && Maze_Wide == 0 && Time == 0 ) break; int i,j; for( i = 0; i < Maze_Wide; i++ ) for( j = 0; j < Maze_Long; j++ ) { cin>>maze[i][j]; if( maze[i][j] == 'S') {S_x = i; S_y = j;} if( maze[i][j] == 'D') {D_x = i; D_y = j;} if( maze[i][j] == 'X') {count++;} } //如果可以走的砖块比时间还少。肯定不可以 if( Maze_Long * Maze_Wide - count -1 < Time ) { cout<<"NO"<<endl; continue; } for( i = 0; i < Maze_Wide; i++ ) for( j = 0; j < Maze_Long; j++ ) check[i][j] = 0; Can = false; time = 0; check[S_x][S_y] = 1; Go( S_x,S_y,time ); if( Can ) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0;}
0 0
- HDU 1010 Tempter of the Bone
- 迷宫 hdu 1010 Tempter of the Bone
- HDU 1010-Tempter of the Bone
- hdu 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- hdu 1010 Tempter of the Bone(深搜)
- HDU 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- hdu 1010 Tempter of the Bone
- HDU-1010-Tempter of the Bone
- hdu 1010 Tempter of the Bone
- HDU 1010-Tempter of the Bone
- HDU 1010 Tempter of the Bone (DFS)
- hdu 1010 Tempter of the Bone
- HDU 1010 - Tempter of the Bone
- hdu 1010 Tempter of the Bone
- HDOJ 1102 Constructing Roads(最小生成树--prime)
- 随机颜色
- 橡皮擦
- IO复用,select、poll、epoll综述
- 企业信息安全白皮书解决方案
- HDU 1010 Tempter of The Bone
- C++ 多线程拷贝文件(demo)
- BestCoder Round #50 digger(动态生成线段树)
- 安卓一键分享解决方案
- IOS--XML解析
- Prime Ring Problem
- jdk安装
- MySQL for Mac 安装和基本操作
- 透彻理解IOC