标签:
http://poj.org/problem?id=1835
Time Limit: 2000MS | Memory Limit: 30000K | |
Total Submissions: 4802 | Accepted: 2058 |
Description
Input
Output
Sample Input
1 6 left 10 right 11 up 12 down 13 forward 14 back 15
Sample Output
23 -10 12 3
Source
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 #include<queue> 5 #include<iostream> 6 #include<stack> 7 #include<map> 8 #include<string> 9 using namespace std; 10 int main(){ 11 char ch[20]; 12 int n, t, tcase; 13 scanf("%d", &tcase); 14 while(tcase--){ 15 scanf("%d", &n); 16 int face, head, x, y, z, num; 17 x = y = z = face = 0; 18 head = 2; 19 for(int i = 0; i < n; i++){ 20 scanf("%s%d", ch, &num); 21 if(ch[0] == ‘f‘){ 22 if(face == 0) x += num; 23 if(face == 1) y += num; 24 if(face == 2) z += num; 25 if(face == 3) x -= num; 26 if(face == 4) y -= num; 27 if(face == 5) z -= num; 28 } 29 else if(ch[0] == ‘b‘){ 30 face = (face+3)%6; 31 if(face == 0) x += num; 32 if(face == 1) y += num; 33 if(face == 2) z += num; 34 if(face == 3) x -= num; 35 if(face == 4) y -= num; 36 if(face == 5) z -= num; 37 } 38 else if(ch[0] == ‘l‘){ 39 if(face == 0 && head == 1) face = 2; 40 else if(face == 0 && head == 4) face = 5; 41 else if(face == 0 && head == 2) face = 4; 42 else if(face == 0 && head == 5) face = 1; 43 44 else if(face == 1 && head == 0) face = 5; 45 else if(face == 1 && head == 3) face = 2; 46 else if(face == 1 && head == 2) face = 0; 47 else if(face == 1 && head == 5) face = 3; 48 49 else if(face == 2 && head == 0) face = 1; 50 else if(face == 2 && head == 3) face = 4; 51 else if(face == 2 && head == 1) face = 3; 52 else if(face == 2 && head == 4) face = 0; 53 54 else if(face == 3 && head == 1) face = 5; 55 else if(face == 3 && head == 4) face = 2; 56 else if(face == 3 && head == 2) face = 1; 57 else if(face == 3 && head == 5) face = 4; 58 59 else if(face == 4 && head == 0) face = 2; 60 else if(face == 4 && head == 3) face = 5; 61 else if(face == 4 && head == 2) face = 3; 62 else if(face == 4 && head == 5) face = 0; 63 64 else if(face == 5 && head == 0) face = 4; 65 else if(face == 5 && head == 3) face = 1; 66 else if(face == 5 && head == 4) face = 3; 67 else if(face == 5 && head == 1) face = 0; 68 69 if(face == 0) x += num; 70 if(face == 1) y += num; 71 if(face == 2) z += num; 72 if(face == 3) x -= num; 73 if(face == 4) y -= num; 74 if(face == 5) z -= num; 75 } 76 else if(ch[0] == ‘r‘){ 77 if(face == 0 && head == 1) face = 5; 78 else if(face == 0 && head == 4) face = 2; 79 else if(face == 0 && head == 2) face = 1; 80 else if(face == 0 && head == 5) face = 4; 81 82 else if(face == 1 && head == 0) face = 2; 83 else if(face == 1 && head == 3) face = 5; 84 else if(face == 1 && head == 2) face = 3; 85 else if(face == 1 && head == 5) face = 0; 86 87 else if(face == 2 && head == 0) face = 4; 88 else if(face == 2 && head == 3) face = 1; 89 else if(face == 2 && head == 1) face = 0; 90 else if(face == 2 && head == 4) face = 3; 91 92 else if(face == 3 && head == 1) face = 2; 93 else if(face == 3 && head == 4) face = 5; 94 else if(face == 3 && head == 2) face = 4; 95 else if(face == 3 && head == 5) face = 1; 96 97 else if(face == 4 && head == 0) face = 5; 98 else if(face == 4 && head == 3) face = 2; 99 else if(face == 4 && head == 2) face = 0; 100 else if(face == 4 && head == 5) face = 3; 101 102 else if(face == 5 && head == 0) face = 1; 103 else if(face == 5 && head == 3) face = 4; 104 else if(face == 5 && head == 4) face = 0; 105 else if(face == 5 && head == 1) face = 3; 106 107 if(face == 0) x += num; 108 if(face == 1) y += num; 109 if(face == 2) z += num; 110 if(face == 3) x -= num; 111 if(face == 4) y -= num; 112 if(face == 5) z -= num; 113 } 114 else if(ch[0] == ‘u‘){ 115 t = face; 116 face = head; 117 head = (t+3)%6; 118 if(face == 0) x += num; 119 if(face == 1) y += num; 120 if(face == 2) z += num; 121 if(face == 3) x -= num; 122 if(face == 4) y -= num; 123 if(face == 5) z -= num; 124 } 125 else if(ch[0] == ‘d‘){ 126 t = face; 127 face = (head+3)%6; 128 head = t; 129 if(face == 0) x += num; 130 if(face == 1) y += num; 131 if(face == 2) z += num; 132 if(face == 3) x -= num; 133 if(face == 4) y -= num; 134 if(face == 5) z -= num; 135 } 136 //printf("%d %d %d %d %d\n", x, y, z, face, head); 137 } 138 printf("%d %d %d %d\n", x, y, z, face); 139 } 140 return 0; 141 }
标签:
原文地址:http://www.cnblogs.com/jeff-wgc/p/4482994.html