UVaLive/LA 6802 Turtle Graphics(水题)
来源:互联网 发布:怎么p淘宝的代收货 编辑:程序博客网 时间:2024/05/17 04:26
6802 - Turtle Graphics
题目大意:
类似贪吃蛇游戏。问经过给定路径(F-向前,L-左拐,R-右拐)后的终点坐标,和经过两次以上的点数。
解题思路:
模拟一下即可。
参考代码:
#include <iostream>#include <cstring>#include <string>#include <cstdio>using namespace std;const int MAXN = 100;const int dx[4] = {0, 1, 0, -1};const int dy[4] = {1, 0, -1, 0};int nCase, cCase, x, y, ans;string str;int visited[MAXN][MAXN];void init() { memset(visited, 0, sizeof(visited)); ans = 0;}void input() { scanf("%d%d", &x, &y); cin >> str;}void solve() { int direct = 0; visited[x][y] = true; for (int i = 0; i < str.length(); i++) { if (str[i] == 'F') { x += dx[direct]; y += dy[direct]; if (visited[x][y] == 1) { ans++; } visited[x][y]++; } if (str[i] == 'L') { direct = (direct - 1 + 4) % 4; } if (str[i] == 'R') { direct = (direct + 1) % 4; } } printf("Case #%d: %d %d %d\n", ++cCase, x, y, ans);}int main() { scanf("%d", &nCase); while (nCase--) { init(); input(); solve(); } return 0;}
0 0
- UVaLive/LA 6802 Turtle Graphics(水题)
- UVALive - 6802 Turtle Graphics
- UVaLive/LA 6801 Sequence(DP)
- UVaLive/LA 6805 Pantun Grader(模拟)
- LA 4329/uvalive 4329 (树状数组)
- UVaLive(LA) 3902 Network,Seoul 2007
- 简单的海龟绘图语言(Design a Turtle Graphics language which can be used to draw "L" graphics)
- UVALive(LA) 3644 X-Plosives (并查集)
- UVaLive LA 4356 - Fire-Control System (扫描法 思维)
- UVaLive LA 4256 | UVa 1424 - Salesmen(简单DP)
- UVaLive ( LA ) 3516 - Exploring Pyramids (DP 递推)
- UVaLive/LA 6804 Group of Strangers(图论)
- UVaLive/LA 6806 Hari Merdeka(AC自动机,DP)
- UVaLive/LA 6809 Spokes Wheel(搜索,二进制循环移位)
- UVALive - 4256 || LA 4256 Salesmen 商人(DP)
- UVaLive 2678(LA)Subsequence SEERC 2006 题解
- Turtle
- UVALive(LA) 4487 Exclusive-OR(带权并查集)
- NYOJ47过河问题
- 1、Intent和IntentFilter详解
- 1012. 数字分类 (20) (数学啊 ZJU_PAT)
- 解决SQLite数据库中文乱码问题
- Java IO
- UVaLive/LA 6802 Turtle Graphics(水题)
- POJ2484A Funny Game
- 四姐夫还是老样子走到哪里
- 五陈克复笑了笑
- 人品计算器的设计
- 经雪花五般的飞起了京城了
- lang包(上)
- 每个Java开发者都应该知道的5个JDK工具
- 字符串排序--低位优先法