程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> 1573 Robot Motion

1573 Robot Motion

編輯:C++入門知識

Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10219 Accepted: 4977

Description

\

A robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in a grid. The pZ喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vc3NpYmxlIGluc3RydWN0aW9ucyBhcmUgPGJyPgo8YnI+Ck4gbm9ydGggKHVwIHRoZSBwYWdlKSA8YnI+ClMgc291dGggKGRvd24gdGhlIHBhZ2UpIDxicj4KRSBlYXN0ICh0byB0aGUgcmlnaHQgb24gdGhlIHBhZ2UpIDxicj4KVyB3ZXN0ICh0byB0aGUgbGVmdCBvbiB0aGUgcGFnZSkgPGJyPgo8YnI+CkZvciBleGFtcGxlLCBzdXBwb3NlIHRoZSByb2JvdCBzdGFydHMgb24gdGhlIG5vcnRoICh0b3ApIHNpZGUgb2YgR3JpZCAxIGFuZCBzdGFydHMgc291dGggKGRvd24pLiBUaGUgcGF0aCB0aGUgcm9ib3QgZm9sbG93cyBpcyBzaG93bi4gVGhlIHJvYm90IGdvZXMgdGhyb3VnaCAxMCBpbnN0cnVjdGlvbnMgaW4gdGhlIGdyaWQgYmVmb3JlIGxlYXZpbmcgdGhlIGdyaWQuIDxicj4KPGJyPgpDb21wYXJlIHdoYXQgaGFwcGVucyBpbiBHcmlkIDI6IHRoZSByb2JvdCBnb2VzIHRocm91Z2ggMyBpbnN0cnVjdGlvbnMgb25seSBvbmNlLCBhbmQgdGhlbiBzdGFydHMgYSBsb29wIHRocm91Z2ggOCBpbnN0cnVjdGlvbnMsIGFuZCBuZXZlciBleGl0cy4gPGJyPgo8YnI+CllvdSBhcmUgdG8gd3JpdGUgYSBwcm9ncmFtIHRoYXQgZGV0ZXJtaW5lcyBob3cgbG9uZyBpdCB0YWtlcyBhIHJvYm90IHRvIGdldCBvdXQgb2YgdGhlIGdyaWQgb3IgaG93IHRoZSByb2JvdCBsb29wcyBhcm91bmQuIDxicj4KCjxwIGNsYXNzPQ=="pst">Input

There will be one or more grids for robots to navigate. The data for each is in the following form. On the first line are three integers separated by blanks: the number of rows in the grid, the number of columns in the grid, and the number of the column in which the robot enters from the north. The possible entry columns are numbered starting with one at the left. Then come the rows of the direction instructions. Each grid will have at least one and at most 10 rows and columns of instructions. The lines of instructions contain only the characters N, S, E, or W with no blanks. The end of input is indicated by a row containing 0 0 0.

Output

For each grid in the input there is one line of output. Either the robot follows a certain number of instructions and exits the grid on any one the four sides or else the robot follows the instructions on a certain number of locations once, and then the instructions on some number of locations repeatedly. The sample input below corresponds to the two grids above and illustrates the two forms of output. The word "step" is always immediately followed by "(s)" whether or not the number before it is 1.

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

Mid-Central USA 1999

http://poj.org/problem?id=1573

//主要是判斷是否構成循環,根據題目特點,可以設置一個標記數組,如果走過了就不能在走,直到退出循環。

用另外一個數組表示到這一個坐標的步數。那麼退出循環的時候其實已經到以前走過的點,輸出步數,然後循環節就是總步數減去當前步數。

#include
#include
int main()
{
	int n,m,k,l,p,step;
	char s[11][11];
	int map[11][11];
	while(scanf("%d %d",&n,&m)!=EOF)
	{
		if(n==0||m==0)break;
		scanf("%d",&k);
		for(int i=0;i=0&&l=0&&p


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved