POJ 1835 宇航员

模拟。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-8;
void File()
{
    freopen("D:\\in.txt","r",stdin);
    freopen("D:\\out.txt","w",stdout);
}

char op[20];
int T,x,y,z,n,m,d,f1,f2;

int main()
{
    scanf("%d",&T); 
    while(T--)
    {
        scanf("%d",&n); x=0,y=0,z=0,d=0,f1=4,f2=2;
        for(int i=1;i<=n;i++)
        {
            int L,tmp=d; scanf("%s%d",op,&L);
            
            if(op[0]=='b') d=(d+3)%6, f1=(f1+3)%6;
            
            else if(op[0]=='l') d=f1, f1=(tmp+3)%6;
            else if(op[0]=='u') d=f2, f2=(tmp+3)%6;
            
            else if(op[0]=='r') d=(f1+3)%6, f1=tmp;
            else if(op[0]=='d') d=(f2+3)%6, f2=tmp;
            
            if(d==0) x=x+L; if(d==3) x=x-L;
            if(d==1) y=y+L; if(d==4) y=y-L;
            if(d==2) z=z+L; if(d==5) z=z-L;
        }
        printf("%d %d %d %d\n",x,y,z,d);
    }
    return 0;
}

 

posted @ 2016-08-25 17:10  Fighting_Heart  阅读(144)  评论(0编辑  收藏  举报