hdu1026还是搜索

Problem C

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 2   Accepted Submission(s) : 2
Special Judge
Font: Times New Roman | Verdana | Georgia
Font Size: ← →

Problem Description

The Princess has been abducted by the BEelzebub feng5166, our hero Ignatius has to rescue our pretty Princess. Now he gets into feng5166's castle. The castle is a large labyrinth. To make the problem simply, we assume the labyrinth is a N*M two-dimensional array which left-top corner is (0,0) and right-bottom corner is (N-1,M-1). Ignatius enters at (0,0), and the door to feng5166's room is at (N-1,M-1), that is our target. There are some monsters in the castle, if Ignatius meet them, he has to kill them. Here is some rules:

1.Ignatius can only move in four directions(up, down, left, right), one step per second. A step is defined as follow: if current position is (x,y), after a step, Ignatius can only stand on (x-1,y), (x+1,y), (x,y-1) or (x,y+1).
2.The array is marked with some characters and numbers. We define them like this:
. : The place where Ignatius can walk on.
X : The place is a trap, Ignatius should not walk on it.
n : Here is a monster with n HP(1<=n<=9), if Ignatius walk on it, it takes him n seconds to kill the monster.

Your task is to give out the path which costs minimum seconds for Ignatius to reach target position. You may assume that the start position and the target position will never be a trap, and there will never be a monster at the start position.

Input

The input contains several test cases. Each test case starts with a line contains two numbers N and M(2<=N<=100,2<=M<=100) which indicate the size of the labyrinth. Then a N*M two-dimensional array follows, which describe the whole labyrinth. The input is terminated by the end of file. More details in the Sample Input.

Output

For each test case, you should output "God please help our poor hero." if Ignatius can't reach the target position, or you should output "It takes n seconds to reach the target position, let me show you the way."(n is the minimum seconds), and tell our hero the whole path. Output a line contains "FINISH" after each test case. If there are more than one path, any one is OK in this problem. More details in the Sample Output.

Sample Input

5 6
.XX.1.
..X.2.
2...X.
...XX.
XXXXX.
5 6
.XX.1.
..X.2.
2...X.
...XX.
XXXXX1
5 6
.XX...
..XX1.
2...X.
...XX.
XXXXX.

Sample Output

It takes 13 seconds to reach the target position, let me show you the way.
1s:(0,0)->(1,0)
2s:(1,0)->(1,1)
3s:(1,1)->(2,1)
4s:(2,1)->(2,2)
5s:(2,2)->(2,3)
6s:(2,3)->(1,3)
7s:(1,3)->(1,4)
8s:FIGHT AT (1,4)
9s:FIGHT AT (1,4)
10s:(1,4)->(1,5)
11s:(1,5)->(2,5)
12s:(2,5)->(3,5)
13s:(3,5)->(4,5)
FINISH
It takes 14 seconds to reach the target position, let me show you the way.
1s:(0,0)->(1,0)
2s:(1,0)->(1,1)
3s:(1,1)->(2,1)
4s:(2,1)->(2,2)
5s:(2,2)->(2,3)
6s:(2,3)->(1,3)
7s:(1,3)->(1,4)
8s:FIGHT AT (1,4)
9s:FIGHT AT (1,4)
10s:(1,4)->(1,5)
11s:(1,5)->(2,5)
12s:(2,5)->(3,5)
13s:(3,5)->(4,5)
14s:FIGHT AT (4,5)
FINISH
God please help our poor hero.
FINISH
代码:
#include<iostream>
#include<cstdio>
using namespace std;
const int maxn = 10010;
struct Node{
 int x,y,t;
 Node(){}
 Node(int a,int b,int c){x=a,y=b,t=c;}
}path[maxn],que[maxn*9];
int n,m;
int fx[]={1,-1,0,0};
int fy[]={0,0,1,-1};
char map[110][110];
int vis[110][110],f[110][110];
int bfs(){
 int k,s,t,i,j,nx,ny;
 for(i=0;i<n;i++){
  scanf("%s",map[i]);
  for(j=0;j<m;j++) // 将所有可走的地方,标记为0个怪 
   if(map[i][j]=='.') map[i][j]='0';
 }
 que[s=t=0]=Node(0,0,map[0][0]-'0');
 memset(vis,-1,sizeof(vis));
 vis[0][0]=0;
 while(s<=t){
  Node no=que[s++];
  if(no.t){ // 原地还有怪 , 就停留在原地打 
   que[++t]=Node(no.x,no.y,no.t-1);
   vis[no.x][no.y]++;
   continue;
  }
  if(n-1==no.x && m-1==no.y) break; //  到重点则退出 
  for(k=0;k<4;k++){
   nx=no.x+fx[k];
   ny=no.y+fy[k];
   if(nx<0 || ny<0 || nx>=n || ny>=m) continue;
   if(map[nx][ny]=='X' || vis[nx][ny]!=-1) continue;
   vis[nx][ny]=vis[no.x][no.y]+1;
   f[nx][ny]=k; // 标记走的方向 
   que[++t]=Node(nx,ny,map[nx][ny]-'0'); 
  }
 }
 return vis[n-1][m-1]; // 返回到达终点的步数 
}
int main(){
 int step,tol,x,y,nx,ny;
 while(~scanf("%d%d",&n,&m)){
  tol=bfs();
  if(tol==-1) // 无法到达 
   puts("God please help our poor hero.");
  else{
   step=0;
   x=n-1,y=m-1;
   while(x || y){ // 通过f[][]记录的方向,我们可以知道是从哪个坐标走到这一个坐标的,通过这个方式将路线导出到path 
    path[step++]=Node(x,y,map[x][y]-'0');
    nx=x+fx[f[x][y]^1],ny=y+fy[f[x][y]^1];
    x=nx,y=ny;
   }
   path[step]=Node(0,0,map[0][0]-'0');
   printf("It takes %d seconds to reach the target position, let me show you the way.\n",tol);
   int t=0;
   while(step--){ // 输出路线 
    printf("%ds:(%d,%d)->(%d,%d)\n",++t,path[step+1].x,path[step+1].y,path[step].x,path[step].y);
    while(path[step].t--) printf("%ds:FIGHT AT (%d,%d)\n",++t,path[step].x,path[step].y);
   }
  }
  puts("FINISH");
 }
 return 0;
}
智慧旅游解决方案利用云计算、物联网和移动互联网技术,通过便携终端设备,实现对旅游资源、经济、活动和旅游者信息的智能感知和发布。这种技术的应用旨在提升游客在旅游各个环节的体验,使他们能够轻松获取信息、规划行程、预订票务和安排食宿。智慧旅游平台为旅游管理部门、企业和游客提供服务,包括政策发布、行政管理、景区安全、游客流量统计分析、投诉反馈等。此外,平台还提供广告促销、库存信息、景点介绍、电子门票、社交互动等功能。 智慧旅游的建设规划得到了国家政策的支持,如《国家中长期科技发展规划纲要》和国务院的《关于加快发展旅游业的意见》,这些政策强调了旅游信息服务平台的建设和信息化服务的重要性。随着技术的成熟和政策环境的优化,智慧旅游的时机已经到来。 智慧旅游平台采用SaaS、PaaS和IaaS等云服务模式,提供简化的软件开发、测试和部署环境,实现资源的按需配置和快速部署。这些服务模式支持旅游企业、消费者和管理部门开发高性能、高可扩展的应用服务。平台还整合了旅游信息资源,提供了丰富的旅游产品创意平台和统一的旅游综合信息库。 智慧旅游融合应用面向游客和景区景点主管机构,提供无线城市门户、智能导游、智能门票及优惠券、景区综合安防、车辆及停车场管理等服务。这些应用通过物联网和云计算技术,实现了旅游服务的智能化、个性化和协同化,提高了旅游服务的自由度和信息共享的动态性。 智慧旅游的发展标志着旅游信息化建设的智能化和应用多样化趋势,多种技术和应用交叉渗透至旅游行业的各个方面,预示着全面的智慧旅游时代已经到来。智慧旅游不仅提升了游客的旅游体验,也为旅游管理和服务提供了高效的技术支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值