Robot Motion(imitate)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 11065 | Accepted: 5378 |
Description

N north (up the page) S south (down the page) E east (to the right on the page) W west (to the left on the page)
For example, suppose the robot starts on the north (top) side of Grid 1 and starts south (down). The path the robot follows is shown. The robot goes through 10 instructions in the grid before leaving the grid.
Compare what happens in Grid 2: the robot goes through 3 instructions only once, and then starts a loop through 8 instructions, and never exits.
You are to write a program that determines how long it takes a robot to get out of the grid or how the robot loops around.
Input
Output
Sample Input
- 3 6 5
- NEESWE
- WWWESS
- SNWWWW
- 4 5 1
- SESWE
- EESNW
- NWEEN
- EWSEN
- 0 0 0
Sample Output
- 10 step(s) to exit
- 3 step(s) before a loop of 8 step(s)
Source
- #include<stdio.h>
- #include<string.h>
- #include<iostream>
- using namespace std;
- int row , col , o ;
- char map[][] ;
- int a[][] ;
- int x , y ;
- void loop (char dir)
- {
- switch (dir)
- {
- case 'N' : printf ("%d step(s) before a loop of %d step(s)\n" , a[x][y] - , a[x + ][y] - a[x][y] + ) ; break ;
- case 'E' : printf ("%d step(s) before a loop of %d step(s)\n" , a[x][y] - , a[x][y - ] - a[x][y] + ) ; break ;
- case 'S' : printf ("%d step(s) before a loop of %d step(s)\n" , a[x][y] - , a[x - ][y] - a[x][y] + ) ; break ;
- case 'W' : printf ("%d step(s) before a loop of %d step(s)\n" , a[x][y] - , a[x][y + ] - a[x][y] + ) ; break ;
- }
- }
- void solve ()
- {
- x = , y = o ;
- bool flag = ;
- char temp ;
- a[x][y] = ;
- while (x >= && x <= row && y >= && y <= col) {
- switch (map[x][y])
- {
- case 'N' : x-- ; if (a[x][y]) flag = ;
- if (!flag)
- a[x][y] = a[x + ][y] + ;
- else
- temp = 'N' ; break ;
- case 'E' : y++ ; if (a[x][y]) flag = ;
- if (!flag)
- a[x][y] = a[x][y - ] + ;
- else
- temp = 'E' ; break ;
- case 'S' : x++ ; if (a[x][y]) flag = ;
- if (!flag)
- a[x][y] = a[x - ][y] + ;
- else
- temp = 'S' ; break ;
- case 'W' : y-- ; if (a[x][y]) flag = ;
- if (!flag)
- a[x][y] = a[x][y + ] + ;
- else
- temp = 'W' ; break ;
- }
- if (flag) {
- loop (temp) ;
- break ;
- }
- }
- if (!flag)
- printf ("%d step(s) to exit\n" , a[x][y] - ) ;
- }
- int main ()
- {
- // freopen ("a.txt" , "r" , stdin) ;
- while (~ scanf ("%d%d%d" , &row , &col , &o)) {
- if (row == && col == && o == )
- break ;
- memset (a , , sizeof(a)) ;
- for (int i = ; i <= row ; i++)
- for (int j = ; j <= col ; j++)
- cin >> map[i][j] ;
- solve () ;
- /* for (int i = 1 ; i <= row ; i++) {
- for (int j = 1 ; j <= col ; j++) {
- printf ("%d " , a[i][j]) ;
- }
- puts ("") ;
- }
- printf ("\n\n") ;*/
- }
- return ;
- }
Robot Motion(imitate)的更多相关文章
- poj1573 Robot Motion
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12507 Accepted: 6070 Des ...
- 模拟 POJ 1573 Robot Motion
题目地址:http://poj.org/problem?id=1573 /* 题意:给定地图和起始位置,robot(上下左右)一步一步去走,问走出地图的步数 如果是死循环,输出走进死循环之前的步数和死 ...
- POJ 1573 Robot Motion(BFS)
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12856 Accepted: 6240 Des ...
- Robot Motion 分类: POJ 2015-06-29 13:45 11人阅读 评论(0) 收藏
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11262 Accepted: 5482 Descrip ...
- POJ 1573 Robot Motion
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12978 Accepted: 6290 Des ...
- Poj OpenJudge 百练 1573 Robot Motion
1.Link: http://poj.org/problem?id=1573 http://bailian.openjudge.cn/practice/1573/ 2.Content: Robot M ...
- POJ1573——Robot Motion
Robot Motion Description A robot has been programmed to follow the instructions in its path. Instruc ...
- hdoj 1035 Robot Motion
Robot Motion Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- HDU-1035 Robot Motion
http://acm.hdu.edu.cn/showproblem.php?pid=1035 Robot Motion Time Limit: 2000/1000 MS (Java/Others) ...
随机推荐
- 连贯接口(fluent interface)的Java实现及应用。
几年前在单元测试时使用mockito和junit(使用hamcrest提供的比较方法)的时候,就用到过这样类似的语法: mockito: when(mock.someMethod("some ...
- 学习笔记——Maven实战(九)打包的技巧
“打包“这个词听起来比较土,比较正式的说法应该是”构建项目软件包“,具体说就是将项目中的各种文件,比如源代码.编译生成的字节码.配置文件.文档,按照规范的格式生成归档,最常见的当然就是JAR包和WAR ...
- 转 Windows server 2008 搭建VPN服务
VPN英文全称是“Virtual Private Network”,就是“虚拟专用网络”. 虚拟专用网络就是一种虚拟出来的企业内部专用线路.这条隧道可以对数据进行几倍加密达到安全使用互联网的目的. ...
- brew-cask 之本地更新 node
本文同步自我的个人博客:http://www.52cik.com/2015/11/04/brew-cask-local.html 今天 Node v4.2.2 (LTS) 发布,什么是 LTS 呢,百 ...
- grootJS ui控件定义
index13.html <html><head> <title>ui控件定义</title> <script src="jquery- ...
- Orchard 刨析:Caching
关于Orchard中的Caching组件已经有一些文章做了介绍,为了系列的完整性会再次对Caching组件进行一次介绍. 缓存的使用 在Orchard看到如下一段代码: 可以看到使用缓存的方法Get而 ...
- css渐变
常这样去定义一个渐变的div: 渐变1:(双色) background: -moz-linear-gradient(top, #456d6c %, #32b66a %); %,#456d6c), co ...
- [USACO2005][poj2229]Sumsets(递推)
http://poj.org/problem?id=2229 分析: 显然的递推 若n为奇数,那么肯定是在n-1的基础上前面每个数+1,即f[n]=f[n-1] 若n为偶数 当第一位数字是1的时候,等 ...
- Struts2 标签分类
- java 关键字 transient
一个对象实现了Serilizable 接口,该对象就可以被序列化. 然而在实际开发工程中,我们会遇到,这个类的有些属性不需要序列化,比如包含用户的敏感信息(如密码),为了安全起见,不希望在网络操作(主 ...