zcmu-1905
来源:互联网 发布:天宇网络 编辑:程序博客网 时间:2024/06/06 17:35
1905: Treasure Hunt
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 66 Solved: 32
[Submit][Status][Web Board]
Description
Treasure Hunt
Jill has created a new smartphone game that leads players to find a treasure. The app uses the phone's GPS to determine the player's location. The app then tells the player the direction in which to go on a route to find the treasure. When the player reaches some specific location, the app rewards the player with a (virtual) treasure.
Can you help the player determine how long it will take to find the treasure?
Input
The first line of input contains two integers R and C, each between 1 and 200, inclusive. These integers define the number of rows and columns in the playing area, respectively. The next R lines of input describe the playing area. Each line contains exactly C letters, and each letter defines the action to take in each location in the playing area. There are five possible letters: N indicates a move to the previous row, S indicates a move to the next row, W indicates a move to the previous column, E indicates a move to the next column, and T indicates the location of the treasure. Exactly one location contains the treasure.
Output
The player begins playing at the location in the first column of the first row. The player follows the directions at each location. If the player eventually reaches the treasure by following the directions, output a line containing an integer, the number of moves required to reach the treasure. If the directions cause the player to leave the playing area, output a line containing the word Out. If the directions cause the player to stay in the playing area but never reach the treasure, output a line containing the word Lost.
Sample Input
Sample Output
HINT
Source
Ondřej Lhoták
题意:求从起点到终点要走多少步,若到达不了,输出Lost
思路;模拟走路的过程就可以。
代码:
#include<bits/stdc++.h>using namespace std;int main(){ char a[250][250]; int f[250][250]; int n,m; while(~scanf("%d%d",&n,&m)) { memset(f,0,sizeof(f)); memset(a,'0',sizeof(a)); for(int i=1; i<=n; i++){ getchar(); for(int j=1; j<=m; j++) scanf("%c",&a[i][j]); } int i=1,j=1; int flag1=0,flag2=0,count=0; while(a[i][j]!='T') { if(f[i][j])break; f[i][j]=1; if(a[i][j]=='N') { i--; if(a[i][j]=='0') { flag1=1; } else if(a[i][j]=='T') { count++; break; } else count++; } else if(a[i][j]=='S') { i++; if(a[i][j]=='0') { flag1=1; } else if(a[i][j]=='T') { count++; break; } else count++; } else if(a[i][j]=='W') { j--; if(a[i][j]=='0') { flag1=1; } else if(a[i][j]=='T') { count++; break; } else count++; } else if(a[i][j]=='E') { j++; if(a[i][j]=='0') { flag1=1; } else if(a[i][j]=='T') { count++; break; } else count++; } if(flag1)break; } //printf("%d %d\n",i,j); if(flag1) printf("Out\n"); else if(f[i][j]) printf("Lost\n"); else printf("%d\n",count); } return 0;}
- zcmu-1905
- zcmu-1657
- zcmu-1685
- ZCMU----1776
- ZCMU----1777
- ZCMU----1778
- ZCMU----1779
- ZCMU-1731
- ZCMU-1658
- ZCMU-1654
- ZCMU-1132
- ZCMU-1037
- ZCMU-1415
- ZCMU-1036
- ZCMU-1723
- ZCMU-1608
- ZCMU-1478
- ZCMU-1750
- Tarjan 算法&模板
- Server Tomcat v8.5 Server at localhost was unable to start within 45 seconds. If the server requir报错
- 第七篇:深入浅出UML类图(四)
- app性能测试工具总结(7)
- 代码中特殊的注释技术——TODO、FIXME和XXX的用处
- zcmu-1905
- 【转】mybatis生成逆向工程后对对数据库的模糊查询以及如何联表查询
- 关于在工作中使用dubbo和zookeeper的一些理解
- 常用网址
- Spring-loaded实现热部署-开发环境
- jquery语法
- 被2345篡改主页
- @Autowired和@Resource的区别是什么?
- 51Nod-1066-Bash游戏