UVa 118 - Mutant Flatworld Explorers

题目:给你一个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;
}
时间: 2024-08-09 10:01:18

UVa 118 - Mutant Flatworld Explorers的相关文章

HOJ 题目分类

转自:http://blog.sina.com.cn/s/blog_65f3869301011a1o.html ******************************************************************************* 简单题(包括枚举,二分查找,(复杂)模拟,基础数据结构(栈.队列),杂题等 ****************************************************************************

[题解]UVa 12661 Funny Car Racing - spfa

很简单的一道最短路问题.分情况处理赛道的打开和关闭. Code 1 /** 2 * UVa 3 * Problem#12661 4 * Accepted 5 * Time:50ms 6 */ 7 #include<iostream> 8 #include<fstream> 9 #include<sstream> 10 #include<cstdio> 11 #include<cstdlib> 12 #include<cstring>

[题解]UVa 11082 Matrix Decompressing

开始眨眼一看怎么也不像是网络流的一道题,再怎么看也觉得像是搜索.不过虽然这道题数据范围很小,但也不至于搜索也是可以随随便便就可以过的.(不过这道题应该是special judge,因为一题可以多解而且题目中然而并没有什么要求,所以说可以考虑思考一下这道题有木有什么"套路"之类的通法) 比如说有这么一组数据 原矩阵 1 2 3 4 7 8 9 5 6 输入 3 3 6 25 45 14 28 45 然后将每一行的和写在每一列对应的行上(很明显有问题) 6 0 0 19 0 0 20 0

[uva] 10099 - The Tourist Guide

10099 - The Tourist Guide 题目页:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1040 Mr.G.自己也算一个人……… 反映到代码里是127行 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 3

UVA - 620Cellular Structure(递推)

题目:UVA - 620Cellular Structure(递推) 题目大意:只能给出三种细胞的增殖方式,然后给出最后细胞的增殖结果,最后问你这是由哪一种增殖方式得到的.如果可以由多种增殖方式得到,就输出题目中列出来的增殖方式靠前的那种. 解题思路:也是递推,细胞长度长的可以由细胞长度短的推得,并且这里第一种只能是长度为1的细胞才有可能,所以判断的时候可以3个判断,看能否与上面的增殖结果匹配,可以的话就记录下来,以后的长串就是由这样的短串再加上两个细胞继续往后推. 例如: BAABA 将A变为

uva 3592 (MST, kruskal)

题意:平面上有若干个点,求最小生成树.有最多8个套餐,每个套餐有一个价格和若干个点,一旦购买套餐内的点就会相互连通. 思路:由于套餐不是很多,所以枚举一下即可,然后最小生成树就行了. 代码如下: 1 /************************************************** 2 * Author : xiaohao Z 3 * Blog : http://www.cnblogs.com/shu-xiaohao/ 4 * Last modified : 2014-06-

UVa 11888 Abnormal 89&#39;s

方法:Manacher Manacher算法在O(length) 时间内求出各个回文子串的长度.O(length) 时间检查时那一种情况. code: 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <iostream> 5 #include <string> 6 #include <vector> 7 #include <st

UVA 658 It&#39;s not a Bug, it&#39;s a Feature! (单源最短路,dijkstra+优先队列,变形,经典)

题意:有n个bug,有m个补丁,每个补丁有一定的要求(比如某个bug必须存在,某个必须不存在,某些无所谓等等),打完出来后bug还可能变多了呢.但是打补丁是需要时间的,每个补丁耗时不同,那么问题来了:要打多久才能无bug?(同1补丁可重复打) 分析: n<=20,那么用位来表示bug的话有220=100万多一点.不用建图了,图实在太大了,用位图又不好玩.那么直接用隐式图搜索(在任意点,只要满足转移条件,任何状态都能转). 但是有没有可能每个状态都要搜1次啊?那可能是100万*100万啊,这样出题

uva 11610 Reverse Prime

Problem FReverse Prime Input: Standard Input Output: Standard Output There are a few 7 digit positive numbers whose reverse number is a prime number and less than 10^6.  For example: 1000070, 1000090 and 1000240 are first few reverse prime numbers be