• POJ 1835 宇航员


                                                                宇航员
    Time Limit: 2000MS   Memory Limit: 30000K
    Total Submissions: 4126   Accepted: 1766

    Description

    问题描述: 
      宇航员在太空中迷失了方向,在他的起始位置现在建立一个虚拟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

    Source

    qinlu@POJ 

    1: (x+3)%6 就是相反的那个方向
     
    2:宇航员的方向由 前面  头顶   右手 三个方向确定
     
    3: 
    向上的方向转换为:
    头顶:换成原来的前面的反方向,前面:换成头顶,右手:方向不变
     
    向下的方向转变为:
    头顶:转换为前方  前面:转换成头顶方向的相反  右手:方向不变
     
    向右的方向转变为:
    头顶:方向不变 前面:转到右手的方向  右手:前面的方向的相反
     
    向左的方向转变为:
    头顶:方向不变 前面:右手方向的相反 右手:前面的方向
     
    向后:
    头顶:不变  前面:原来的相反数  右手:原来的相反数
     
    4:
    对每组输入,先判断状态,在进行相应的坐标移动
      1 #include <iostream>
      2 #include <cstdio>
      3 #include <cstring>
      4 
      5 using namespace std;
      6 
      7 #define fanzuan(x)  ((x)+3)%6
      8 
      9 struct fx
     10 {
     11     int front,top,right;
     12 };
     13 
     14 fx turnback(fx a)
     15 {
     16     fx b;
     17     b.front=fanzuan(a.front);
     18     b.top=a.top;
     19     b.right=fanzuan(a.right);
     20     return b;
     21 }
     22 
     23 fx turnup(fx a)
     24 {
     25     fx b;
     26     b.top=fanzuan(a.front);
     27     b.front=a.top;
     28     b.right=a.right;
     29     return b;
     30 }
     31 
     32 fx turndown(fx a)
     33 {
     34     fx b;
     35     b.top=a.front;
     36     b.front=fanzuan(a.top);
     37     b.right=a.right;
     38     return b;
     39 }
     40 
     41 fx turnright(fx a)
     42 {
     43     fx b;
     44     b.top=a.top;
     45     b.front=a.right;
     46     b.right=fanzuan(a.front);
     47     return b;
     48 }
     49 
     50 fx turnleft(fx a)
     51 {
     52     fx b;
     53     b.top=a.top;
     54     b.front=fanzuan(a.right);
     55     b.right=a.front;
     56     return b;
     57 }
     58 
     59 int main()
     60 {
     61     int T,n;
     62     char str[20],dis;
     63     cin>>T;
     64 while(T--)
     65 {
     66     cin>>n;
     67     fx st;
     68     st.front=0;st.right=1;st.top=2;
     69     int arr[6]={0},d;
     70     while(n--)
     71     {
     72         scanf("%s%d",str,&d);
     73         switch(str[0])
     74         {
     75         case'f':
     76             arr[st.front]+=d;
     77             break;
     78         case'b':
     79             st=turnback(st);
     80             arr[st.front]+=d;
     81             break;
     82         case'r':
     83             st=turnright(st);
     84             arr[st.front]+=d;
     85             break;
     86         case'l':
     87             st=turnleft(st);
     88             arr[st.front]+=d;
     89             break;
     90         case'u':
     91             st=turnup(st);
     92             arr[st.front]+=d;
     93             break;
     94         case'd':
     95             st=turndown(st);
     96             arr[st.front]+=d;
     97             break;
     98         default:
     99             cout<<"fack
    ";
    100         };
    101     }
    102 
    103     int x=0,y=0,z=0;
    104     int face=st.front;
    105     x=arr[0]-arr[3];
    106     y=arr[1]-arr[4];
    107     z=arr[2]-arr[5];
    108 
    109     printf("%d %d %d %d
    ",x,y,z,face);
    110 }
    111 
    112     return 0;
    113 }
  • 相关阅读:
    .NET重构(七):VS报表的制作
    【Linq】标准查询操作符
    1 TaskQueue 实现Task 队列
    1 疑惑处理
    1 JSONP
    1 Web 知识基础
    20 闭包
    1 基础知识
    Web 常用
    【Winform】2 Button
  • 原文地址:https://www.cnblogs.com/CKboss/p/3278855.html
Copyright © 2020-2023  润新知