hdu1010Tempter of the Bone

Tempter of the Bone

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 79712    Accepted Submission(s): 21753


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.
 

Sample Input
  
  
4 4 5 S.X. ..X. ..XD .... 3 4 5 S.X. ..X. ...D 0 0 0
 

Sample Output
  
  
NO YES
 

题目类型:深搜+剪枝(奇偶剪枝)

题意:在一个二维坐标内,给定起点终点,问能否恰好在给定时间T时刻从起点到达终点到达,到达某一点时不能停留,每到达一点时间加一

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
char a[10][10];
int visit[10][10];
int d[4][2]={{-1,0},{0,-1},{1,0},{0,1}};//方向
int N,M,T;
int S1,S2;	//进洞口坐标
int D1,D2;	//出洞口坐标
int flag;
void dfs(int row,int col,int t)
{
	int i;
	if(flag)
		return ;
	if(row<0||row>N||col<0||col>M)
		return ;
	int b=fabs(D1-row)+fabs(D2-col) ;//奇偶剪枝,我不会按照网上别人代码写的
	if(b>T-t||(T-t+b)%2!=0)
	{
		return ;
	}
	if(row==D1&&col==D2)
	{
		if(t==T)
		{
			flag=1;
			return ;
		}
	}
	for(i=0;i<4;i++)
	{
		int x=row+d[i][0] ;		//切记不能row+=d[i][0];
		int y=col+d[i][1] ;
		if(x>=0&&x<=N-1&&y>=0&&y<=M-1&&!visit[x][y])
		{
			visit[x][y]=1;
			dfs(x,y,t+1);
			visit[x][y]=0;
		}
	}
}
int main()
{
	int i,j,num;
	while(scanf("%d%d%d",&N,&M,&T)!=EOF&&M&&N&&T)
	{
		num=0;
		memset(visit,0,sizeof(visit));
		for(i=0;i<N;i++)
		{
			for(j=0;j<M;j++)
			{
				char ch;
				cin>>ch;
				a[i][j]=ch;
				if(a[i][j]=='S')
				{
					S1=i;
					S2=j;
				}
				if(a[i][j]=='D')
				{
					D1=i;
					D2=j;
				}
				if(a[i][j]=='X')
				{
					visit[i][j]=1;
					num++;
				}
			}
		}
		if(N*M-num-1<T)		//“.”的数目少于时间T
		{
			cout<<"NO"<<endl;
			continue;
		}
		flag=0;
		visit[S1][S2]=1;
		dfs(S1,S2,0);
		if(flag)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
VR(Virtual Reality)即虚拟现实,是一种可以创建和体验虚拟世界的计算机技术。它利用计算机生成一种模拟环境,是一种多源信息融合的、交互式的三维动态视景和实体行为的系统仿真,使用户沉浸到该环境中。VR技术通过模拟人的视觉、听觉、触觉等感觉器官功能,使人能够沉浸在计算机生成的虚拟境界中,并能够通过语言、手势等自然的方式与之进行实时交互,创建了一种适人化的多维信息空间。 VR技术具有以下主要特点: 沉浸感:用户感到作为主角存在于模拟环境中的真实程度。理想的模拟环境应该使用户难以分辨真假,使用户全身心地投入到计算机创建的三维虚拟环境中,该环境中的一切看上去是真的,听上去是真的,动起来是真的,甚至闻起来、尝起来等一切感觉都是真的,如同在现实世界中的感觉一样。 交互性:用户对模拟环境内物体的可操作程度和从环境得到反馈的自然程度(包括实时性)。例如,用户可以用手去直接抓取模拟环境中虚拟的物体,这时手有握着东西的感觉,并可以感觉物体的重量,视野中被抓的物体也能立刻随着手的移动而移动。 构想性:也称想象性,指用户沉浸在多维信息空间中,依靠自己的感知和认知能力获取知识,发挥主观能动性,寻求解答,形成新的概念。此概念不仅是指观念上或语言上的创意,而且可以是指对某些客观存在事物的创造性设想和安排。 VR技术可以应用于各个领域,如游戏、娱乐、教育、医疗、军事、房地产、工业仿真等。随着VR技术的不断发展,它正在改变人们的生活和工作方式,为人们带来全新的体验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值