UVALive - 6802 Turtle Graphics

题目链接

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;
	}
}
时间: 2024-08-26 08:06:42

UVALive - 6802 Turtle Graphics的相关文章

海龟绘图(Turtle Graphics)

python2.6版本中后引入的一个简单的绘图工具,叫做海龟绘图(Turtle Graphics),turtle库是python的内部库,使用导入即可 import turtle 先说明一下turtle绘图的基础知识: 1. 画布(canvas) 画布就是turtle为我们展开用于绘图区域, 我们可以设置它的大小和初始位置 1.1 设置画布大小 turtle.screensize(canvwidth=None, canvheight=None, bg=None) 参数分别为画布的宽(单位像素),

Python - Turtle Graphics

1 import turtle #allows us to use the turtles library 2 wn = turtle.Screen() #creates a graphics window 3 wn.bgcolor("lightgreen")#set the window background color 4 5 alex = turtle.Turtle() #create a turtle named alex 6 alex.pensize(3) #set the

python标准库《turtle》

FUNCTIONS Screen() Return the singleton screen object. If none exists at the moment, create a new one and return it, else return the existing one. addshape(name, shape=None) Adds a turtle shape to TurtleScreen's shapelist. Arguments: (1) name is the

用Python的Turtple画图形

不知道各位是否还记得在小学或者初中的时候,我们接触过一种语言叫做logo语言,这个语言可以画正方形,画三角形,画圆.而用Python画图形也有点类似logo语言的意思. 在画图之前,我们需要启动一个模块,turtple.然后在这个turtple下有一个属性叫pen,顾名思义就是画笔的意思.当输入完pen这个属性的时候,idle会打开一个叫Python Turtle Graphics的东西,在屏幕中间有一个三角的原点,这个点就有点类似logo的点,我们就是操作它来回移动留下痕迹.在idle里写完一

Python著名的lib和开发框架(均为转载)

第一,https://github.com/vinta/awesome-python Awesome Python A curated list of awesome Python frameworks, libraries, software and resources. Inspired by awesome-php. Awesome Python Admin Panels Algorithms and Design Patterns Anti-spam Asset Management A

Python教程大纲

缘起:最近想在部门推Python语言,写这个blog主要就是个教程大纲,之前先列出一些资源:Python历史:http://www.docin.com/p-53019548.html                   :http://blog.csdn.net/zhchongyao/article/details/7748668 Python中文社区主站入口:http://woodpecker.org.cn/Python简明教程:http://woodpecker.org.cn/abyteof

python3内置的tkinter参数释疑

最近涉及到需要实现一个桌面UI的小游戏,所以就翻看了一些文档. 当然有介绍使用pyQT5的,但是本机安装的是python3.4,不想卸载掉这个版本,暂时还不能使用pyQT5. pyQT5需要python3.5及以上的版本才能行. 所以就使用python自带的tkinter了. 总的来说,图形界面的使用基本都是相通的,只要学通一个,其他的也会非常方便的入门. 祝各位能够找到自己所需,那么,我这篇文章也就还算有一些价值了. tkinter是Tk interface代表着图形工具接口,当前python

用Python画图

python2.6后引入一个叫做海龟绘图(Turtle Graphics),的绘图工具.turtle库是python的内部库,直接使用即可 import turtle 思路: 1. 确定好需要画的图 2. 创建一个画布,用来画你需要的图. 1.1 画布大小,可以使用默认大小,也可以自定义画布大小. 1.2 画布背景色bgcolor() 1.3 确定起点位置 3. 画笔的设置 1.1 画笔的大小,颜色 1.2 画笔运行属性 2. 定义画布参数 import turtle as t t.screen

EBU5405: 3D Graphics Programming Tools - Coursework 2019

EBU5405: 3D Graphics Programming Tools - Coursework 2019In this coursework you will develop an articulated and interactive object in the shape of acrawling animal using C and OpenGL. The main objectives of this project are to practice anddemonstrate: