题目链接:http://poj.org/problem?id=1835
模拟,很无聊的题目-_-||,把转换方向映射好就可以了,我是对宇航员保存三个方向的向量,那么每次变化方向的时候就方便了。
1 //STATUS:C++_AC_188MS_172KB 2 #include <functional> 3 #include <algorithm> 4 #include <iostream> 5 //#include <ext/rope> 6 #include <fstream> 7 #include <sstream> 8 #include <iomanip> 9 #include <numeric> 10 #include <cstring> 11 #include <cassert> 12 #include <cstdio> 13 #include <string> 14 #include <vector> 15 #include <bitset> 16 #include <queue> 17 #include <stack> 18 #include <cmath> 19 #include <ctime> 20 #include <list> 21 #include <set> 22 #include <map> 23 using namespace std; 24 //define 25 #define pii pair<int,int> 26 #define mem(a,b) memset(a,b,sizeof(a)) 27 #define lson l,mid,rt<<1 28 #define rson mid+1,r,rt<<1|1 29 #define PI acos(-1.0) 30 //typedef 31 typedef __int64 LL; 32 typedef unsigned __int64 ULL; 33 //const 34 const int N=1010; 35 const int INF=0x3f3f3f3f; 36 const int MOD=256,STA=8000010; 37 const LL LNF=1LL<<60; 38 const double EPS=1e-8; 39 const double OO=1e15; 40 const int dx[4]={-1,0,1,0}; 41 const int dy[4]={0,1,0,-1}; 42 const int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 43 //Daily Use ... 44 inline int sign(double x){return (x>EPS)-(x<-EPS);} 45 template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;} 46 template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;} 47 template<class T> inline T Min(T a,T b){return a<b?a:b;} 48 template<class T> inline T Max(T a,T b){return a>b?a:b;} 49 template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);} 50 template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);} 51 template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));} 52 template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));} 53 //End 54 55 struct Node{ 56 int x,y,z; 57 }r1[3],r2[3]; 58 int T,n; 59 60 void re(Node &a,Node b) 61 { 62 a.x=-b.x; 63 a.y=-b.y; 64 a.z=-b.z; 65 } 66 67 int main() 68 { 69 // freopen("in.txt","r",stdin); 70 int i,j,d,x,y,z; 71 char s[20]; 72 Node *p,*q; 73 scanf("%d",&T); 74 while(T--) 75 { 76 x=y=z=0; 77 r1[0].x=1,r1[0].y=0,r1[0].z=0; 78 r1[1].x=0,r1[1].y=1,r1[1].z=0; 79 r1[2].x=0,r1[2].y=0,r1[2].z=1; 80 scanf("%d",&n); 81 while(n--){ 82 scanf("%s%d",s,&d); 83 if(s[0]=='f'){ 84 r2[0]=r1[0],r2[1]=r1[1],r2[2]=r1[2]; 85 } 86 else if(s[0]=='b'){ 87 re(r2[0],r1[0]); 88 re(r2[1],r1[1]); 89 r2[2]=r1[2]; 90 } 91 else if(s[0]=='l'){ 92 re(r2[0],r1[1]); 93 r2[1]=r1[0]; 94 r2[2]=r1[2]; 95 } 96 else if(s[0]=='r'){ 97 r2[0]=r1[1]; 98 re(r2[1],r1[0]); 99 r2[2]=r1[2]; 100 } 101 else if(s[0]=='u'){ 102 r2[0]=r1[2]; 103 r2[1]=r1[1]; 104 re(r2[2],r1[0]); 105 } 106 else { 107 re(r2[0],r1[2]); 108 r2[1]=r1[1]; 109 r2[2]=r1[0]; 110 } 111 112 x+=r2[0].x*d; 113 y+=r2[0].y*d; 114 z+=r2[0].z*d; 115 swap(r2[0],r1[0]); 116 swap(r2[1],r1[1]); 117 swap(r2[2],r1[2]); 118 } 119 120 int ans; 121 if(r1[0].x==1)ans=0; 122 else if(r1[0].y==1)ans=1; 123 else if(r1[0].z==1)ans=2; 124 else if(r1[0].x==-1)ans=3; 125 else if(r1[0].y==-1)ans=4; 126 else ans=5; 127 128 printf("%d %d %d %d\n",x,y,z,ans); 129 } 130 return 0; 131 }