码迷,mamicode.com
首页 > 其他好文 > 详细

UVALive - 6802 Turtle Graphics

时间:2015-04-24 09:06:08      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:

题目链接

https://icpcarchive.ecs.baylor.edu/external/68/6802.pdf

图的标号和二维数组的不太一样,顺时针转90度就舒服多了

#include<iostream>
#include<cstring>
using namespace std;
int vis[100][100];
int start_x, start_y;
int final_x, final_y;
int dirx[4] = { -1, 0, 1, 0 };  //上下左右
int diry[4] = { 0, -1, 0, 1 };
char op[300];
int face;   //0123北西南东
int n;
int main()
{
	int casen;
	cin >> casen;
	for (int cas = 1; cas <= casen; cas++)
	{
		cin >> start_x >> start_y;
		cin >> op;
		memset(vis, 0, sizeof(vis));
		int x = start_x;
		int y = start_y;
		vis[x][y] = 1;
		face = 3;
		n = 0;		
		for (int i = 0; op[i]; i++)
		{
			switch (op[i])
			{
			case 'F':{switch (face)
			{
			case 0:x = x + dirx[0]; y = y + diry[0]; vis[x][y]++; break;
			case 1:x = x + dirx[1]; y = y + diry[1]; vis[x][y]++; break;
			case 2:x = x + dirx[2]; y = y + diry[2]; vis[x][y]++; break;
			case 3:x = x + dirx[3]; y = y + diry[3]; vis[x][y]++; break;
			}
					 break; }
			case 'R':face = (face + 3) % 4; break;
			case 'L':face = (face + 1) % 4; break;
			}
		}
		final_x = x;
		final_y = y;
		for (int i = 0; i < 100; i++)
		for (int j = 0; j < 100; j++)
		{
			if (vis[i][j]>1) n++;
		}
		cout << "Case #" << cas << ": ";
		cout << final_x << " " << final_y << " " << n << endl;
	}
}


UVALive - 6802 Turtle Graphics

标签:

原文地址:http://blog.csdn.net/qq_18738333/article/details/45237107

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!