UVa 10116 - Robot Motion

题目:有一个地图,地图上有运行的规则(移动到东西南北四个方向),现在给你起始点,求最后的状态。

分析:模拟。直接从起始点出发,按照地图的规则移动即可。记录每个点到达时走的步数,计算环。

说明:这题目也很眼熟(⊙_⊙)。

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>

using namespace std;

char maps[100][100];
int  smap[100][100];

int main()
{
	int N,M,X,Y;
	while (~scanf("%d%d%d",&N,&M,&Y) && Y) {
		for (int i = 0 ; i < N ; ++ i)
			scanf("%s",maps[i]);

		memset(smap, 0, sizeof(smap));
		X = 0; Y --;
		int count = 1;
		while (!smap[X][Y] && X >= 0 && X < N && Y >= 0 && Y < M) {
			smap[X][Y] = count ++;
			switch(maps[X][Y]) {
				case 'N': X --;break;
				case 'S': X ++;break;
				case 'W': Y --;break;
				case 'E': Y ++;break;
				default : break;
			}
		}
		if (X >= 0 && X < N && Y >= 0 && Y < M)
			printf("%d step(s) before a loop of %d step(s)\n",smap[X][Y]-1,count-smap[X][Y]);
		else printf("%d step(s) to exit\n",count-1);
	}
	return 0;
}
时间: 2024-10-12 22:26:06

UVa 10116 - Robot Motion的相关文章

hdoj 1035 Robot Motion

Robot Motion Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7974    Accepted Submission(s): 3685 Problem Description A robot has been programmed to follow the instructions in its path. Instruct

POJ 1573 Robot Motion 搜索

Robot Motion Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6297    Accepted Submission(s): 2952 Problem Description A robot has been programmed to follow the instructions in its path. Instruc

hdu1035 Robot Motion (DFS)

Robot Motion Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8180    Accepted Submission(s): 3771 Problem Description A robot has been programmed to follow the instructions in its path. Instruc

poj1573 Robot Motion

题目链接: http://poj.org/problem?id=1573 题目: Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10202   Accepted: 4971 Description A robot has been programmed to follow the instructions in its path. Instructions for the next direct

HDOJ1035 Robot Motion 【模拟】

Robot Motion Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6079    Accepted Submission(s): 2844 Problem Description A robot has been programmed to follow the instructions in its path. Instruc

UVA 12503 Robot Instructions (B)

 Robot Instructions  You have a robot standing on the origin of x axis. The robot will be given some instructions. Your task is to predict its position after executing all the instructions. LEFT: move one unit left (decrease p by 1, where p is the po

Robot Motion(imitate)

Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11065   Accepted: 5378 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

POJ1573——Robot Motion

Robot Motion 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 possible instructions are N north (up the page) S south (down the page)

[ACM] hdu 1035 Robot Motion (模拟或DFS)

Robot Motion Problem 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 possible instructions are N north (up the page) S south (down t