问题描述:

  宇航员在太空中迷失了方向,在他的起始位置现在建立一个虚拟xyz坐标系,称为绝对坐标系,宇航员正面的方向为x轴正方向,头顶方向为z轴正方向,则宇航员的初始状态如下图所示:

  

现对六个方向分别标号,x,y,z正方向分别为0,1,2,负方向分别为3,4,5;称它们为绝对方向。宇航员在宇宙中只沿着与绝对坐标系xyz轴平行的方向行走,但是他不知道自己当前绝对坐标和自己面向的绝对方向。

任务描述:

  请根据宇航员对自己在相对方向上移动的描述确定宇航员最终的绝对坐标和面向的绝对方向。对在相对方向上移动的描述及意义如下:

forward x  向前走x米。

back x 先转向后,再走x米。

left x 先转向左,再走x米。

right x 先转向右,再走x米。

up x 先面向上,再走x米。

down x 先面向下,再走x米。

其中向上和向下如下图所示:

Input

第一行一个正整数m,表示测试数据的组数。每组测试数据第一行是一个正整数n(1<=n<=10000)表示宇航员行走的次数,下面n行每行输入一次相对行走,格式如上所述,其中( 1 <= x <= 10000 为正整数)。

Output

对于每组输入数据输出一行,x y z p, 中间用空格隔开,x y z是宇航员的位置的绝对坐标,p是宇航员面向的绝对方向编号(0<=p <=5)。

Sample Input

1

6

left 10

right 11

up 12

down 13

forward 14

back 15

Sample Output

23 -10 12 3

//模拟题,比赛的时候一脸懵逼,虽然之前在nyoj上有一道机器人的题,不过那是二维坐标,现在是三维。。
//思路:先确定初始位置的前后左右上下,然后在每次改变方向的时候就再次确定一下前后左右上下
//然后把每个方向存在数组中,而数组的第一个元素就是当前所面对的方向,然后再看每次移动多少就行了
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<cstdio>
#include<sstream>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include <ctype.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std; const int maxn=1100;
typedef long long ll;
const int INF=0x3f3f3f3f; int ans[6], temp[6]; ////根据宇航员的上一次状态求出宇航员的下一次的状态值!
////每换一次方向就重新确定一下当前位置的(前/后/左/右/上/下)
int solve(string str, int *a)
{
if (str == "forward")
{
ans[0] = a[0];
ans[1] = a[1];
ans[2] = a[2];
ans[3] = a[3];
ans[4] = a[4];
ans[5] = a[5];
}
else if (str == "back")
{
ans[0] = a[1];
ans[1] = a[0];
ans[2] = a[3];
ans[3] = a[2];
ans[4] = a[4];
ans[5] = a[5];
}
else if (str == "left")
{
ans[0] = a[2];
ans[1] = a[3];
ans[2] = a[1];
ans[3] = a[0];
ans[4] = a[4];
ans[5] = a[5];
}
else if (str == "right")
{
ans[0] = a[3];
ans[1] = a[2];
ans[2] = a[0];
ans[3] = a[1];
ans[4] = a[4];
ans[5] = a[5];
}
else if (str == "up")
{
ans[0] = a[4];
ans[1] = a[5];
ans[2] = a[2];
ans[3] = a[3];
ans[4] = a[1];
ans[5] = a[0];
}
else if (str == "down")
{
ans[0] = a[5];
ans[1] = a[4];
ans[2] = a[2];
ans[3] = a[3];
ans[4] = a[0];
ans[5] = a[1];
}
return 0;
} int main()
{
int t, step,dis;
int i, j, x, y, z, p;
string direction;
cin >> t;
while (t--)
{
cin >> step;
x = y = z = p = 0;
//temp{0~5}代表初始位置的 前、后、左、右、上、下
temp[0]=0, temp[1]=3,temp[2]=4, temp[3]=1, temp[4]=2,temp[5]=5;
for (i = 0; i < step; i++)
{
cin >> direction >> dis;
solve(direction, temp);
for (j = 0; j < 6; j++)
temp[j] = ans[j];
p = ans[0];//宇航员的绝对方向!
if (p == 4)
y -= dis;
else if (p == 1)
y += dis;
else if (p == 0)
x += dis;
else if (p == 3)
x -= dis;
else if (p == 2)
z += dis;
else if (p == 5)
z -= dis;
}
cout << x << " " << y << " " << z << " " << p << endl;
}
return 0;
}

最新文章

  1. Python 静态方法、类方法
  2. antd 学习
  3. python编程(一)汉诺塔
  4. Flex相关案例及资源搜集
  5. Array.prototype.slice.call
  6. chapter3:Collaborative Filtering ---------A Programmer&#39;s Guide to Data Mining
  7. LATEX学习笔记1
  8. visual studio 2015 企业版 序列号及官方下载地址
  9. Spring MVC中各个filter的用法
  10. jquery之下拉列表select
  11. &lt;转&gt;maven发布第三方jar的一些问题
  12. UVa - 1618 - Weak Key
  13. Tomcat 部署项目无法加载静态资源
  14. POJ1469 COURSES 二分图匹配 匈牙利算法
  15. 树莓派上使用mdk3对无线热点进行DoS攻击
  16. js 验证码倒计时
  17. Git Step by Step – (3) Git对象模型
  18. Oracle安装部署之rhel 5.8下静默安装oracle11gr2
  19. NPOI 设置excel 边框
  20. Python编程举例-装饰器

热门文章

  1. 【BZOJ3191】【JLOI2013】卡牌游戏 [DP]
  2. 不可思议的OOM
  3. js中的document.ready
  4. 浅谈Trigger(SimpleTrigger&amp;CronTrigger)
  5. linux系统引导流程
  6. 基于ansj_seg和nlp-lang的简单nlp工具类
  7. Swift 特殊关键字 与符号
  8. 初识ES6
  9. Winfrom窗体间传值
  10. 百度笔试题:malloc/free与new/delete的区别(转)