首页 > 其他 > 详细

UVa 118 - Mutant Flatworld Explorers

时间:2015-04-15 01:00:04      阅读:763      评论:0      收藏:0      [点我收藏+]

题目:给你一个n*m的格子,现在有很多机器人(给定初始坐标和面向)依次在上面行走,问最后的位置和面向,

            如果走到边界就会掉落,并在掉落前的点标记,让后面的机器人不走这个点。

分析:模拟。直接模拟即可,利用循环取余计算相邻方向,利用地图标记不走的点即可。

说明:注意跳过的点是地图上的点,之前有的机器人走过这里后掉下去了,他走这里后也会掉下去就跳过。

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

using namespace std;

int maps[55][55];
int dxy[4][2] = {0,1,1,0,0,-1,-1,0};

int main()
{
	int  n,m,x,xx,y,yy,towards[128];
	char start,steps[105],face[5] = "NESW";
	
	towards['N'] = 0;
	towards['E'] = 1;
	towards['S'] = 2;
	towards['W'] = 3;
	memset(maps, 0, sizeof(maps));
	
	scanf("%d %d",&n,&m);
	while (~scanf("%d %d %c",&x,&y,&start)) {
		scanf("%s",steps);
		
		int face_now = towards[start],flag = 0;
		for (int i = 0; steps[i]; ++ i) {
			if (steps[i] == 'L')
				face_now = (face_now+3)%4;
			if (steps[i] == 'R')
				face_now = (face_now+1)%4;
			if (steps[i] == 'F') {
				xx = x+dxy[face_now][0];
				yy = y+dxy[face_now][1];
				if (xx < 0 || xx > n || yy < 0 || yy > m) {
					if (maps[x][y])
						continue;
					maps[x][y] = 1;
					flag = 1;
					break;
				}
				x = xx;
				y = yy;
			}
		}
		
		printf("%d %d %c",x,y,face[face_now]);
		if (flag)
			printf(" LOST");
		printf("\n");
	}
	
    return 0;
}



UVa 118 - Mutant Flatworld Explorers

原文:http://blog.csdn.net/mobius_strip/article/details/45049733

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!