hlgoj 1766 Cubing

  模拟。下图是我做的小模型。

 

  1 #include <iostream>
  2 #include <stdio.h>
  3 #include <queue>
  4 #include <stdlib.h>
  5 #include <algorithm>
  6 #include <math.h>
  7 #include <iomanip>
  8 #include <stack>
  9 #include <map>
 10 #include <vector>
 11 #include <string>
 12 using namespace std;
 13 /*
 14     剩下的就是正常的代码了
 15 -------------------------------------------------
 16 */
 17 char D[10],T[10],F[10],B[10],L[10],R[10];
 18 void turn_face(char temp[10])   //顺时针旋转一面
 19 {
 20     int i,j;
 21     char t;
 22     t=temp[1];
 23     temp[1]=temp[7];    temp[7]=temp[9];    temp[9]=temp[3];    temp[3]=t;
 24     t=temp[2];
 25     temp[2]=temp[4];    temp[4]=temp[8];    temp[8]=temp[6];    temp[6]=t;
 26     return;
 27 }
 28 void turn_D()
 29 {
 30    // cout<<"turn D\n";
 31     char t[3];
 32     t[0]=F[7];  t[1]=F[8];  t[2]=F[9];
 33     F[7]=L[9];  F[8]=L[6];  F[9]=L[3];
 34     L[9]=B[3];  L[6]=B[2];  L[3]=B[1];
 35     B[3]=R[1];  B[2]=R[4];  B[1]=R[7];
 36     R[1]=t[0];  R[4]=t[1];  R[7]=t[2];
 37     turn_face(D);
 38     return ;
 39 }
 40 
 41 void turn_T()
 42 {
 43     //cout<<"turn T\n";
 44     char t[3];
 45     t[0]=B[7];  t[1]=B[8];  t[2]=B[9]; //R 1,4,7  ->  B 7,8,9
 46     B[7]=L[1];  B[8]=L[4];  B[9]=L[7]; //F 3,2,1  ->  R 1,4,7
 47     L[1]=F[3];  L[4]=F[2];  L[7]=F[1]; //L 9,6,3  ->  F 3,2,1
 48     F[3]=R[9];  F[2]=R[6];  F[1]=R[3]; //t 0,1,2  ->  L 9,6,3
 49     R[9]=t[0];  R[6]=t[1];  R[3]=t[2];
 50     turn_face(T);
 51     return ;
 52 }
 53 void turn_F()
 54 {
 55   //  cout<<"turn F\n";
 56     char t[3];
 57     t[0]=T[7];  t[1]=T[8];  t[2]=T[9];
 58     T[7]=L[3];  T[8]=L[2];  T[9]=L[1];
 59     L[3]=D[3];  L[2]=D[2];  L[1]=D[1];
 60     D[3]=R[3];  D[2]=R[2];  D[1]=R[1];
 61     R[3]=t[0];  R[2]=t[1];  R[1]=t[2];
 62     turn_face(F);
 63     return;
 64 }
 65 void turn_B()
 66 {
 67     //cout<<"turn B\n";
 68     char t[3];
 69     t[0]=D[7];  t[1]=D[8];  t[2]=D[9];
 70     D[7]=L[7];  D[8]=L[8];  D[9]=L[9];
 71     L[7]=T[3];  L[8]=T[2];  L[9]=T[1];
 72     T[3]=R[7];  T[2]=R[8];  T[1]=R[9];
 73     R[7]=t[0];  R[8]=t[1];  R[9]=t[2];
 74     turn_face(B);
 75     return;
 76 }
 77 void turn_R()
 78 {
 79     //cout<<"turn L\n";
 80     char t[3];
 81     t[0]=F[9];  t[1]=F[6];  t[2]=F[3];
 82     F[9]=D[9];  F[6]=D[6];  F[3]=D[3];
 83     D[9]=B[9];  D[6]=B[6];  D[3]=B[3];
 84     B[9]=T[9];  B[6]=T[6];  B[3]=T[3];
 85     T[9]=t[0];  T[6]=t[1];  T[3]=t[2];
 86     turn_face(R);
 87     return;
 88 }
 89 void turn_L()
 90 {
 91    // cout<<"turn R\n";
 92     char t[3];
 93     t[0]=F[1];  t[1]=F[4];  t[2]=F[7];
 94     F[1]=T[1];  F[4]=T[4];  F[7]=T[7];
 95     T[1]=B[1];  T[4]=B[4];  T[7]=B[7];
 96     B[1]=D[1];  B[4]=D[4];  B[7]=D[7];
 97     D[1]=t[0];  D[4]=t[1];  D[7]=t[2];
 98     turn_face(L);
 99     return;
100 }
101 void init()
102 {
103     int i;
104     for(i=0;i<10;++i){
105         D[i]='y';
106         T[i]='w';
107         F[i]='r';
108         B[i]='o';
109         L[i]='g';
110         R[i]='b';
111     }
112     return;
113 }
114 int main()
115 {
116     string order;
117     int n,t;
118     int i;
119     while(cin>>t){
120         while(t--){
121         cin>>n;
122         init();
123         while(n--){
124             cin>>order;
125             if(order[0]=='D'){
126                 if(order[1]=='+')    turn_D();
127                 else   {
128                     turn_D();turn_D();turn_D();
129                 }
130             }
131             else if(order[0]=='U'){
132                 if(order[1]=='+')    turn_T();
133                 else   {
134                     turn_T();turn_T();turn_T();
135                 }
136             }
137             else if(order[0]=='F'){
138                 if(order[1]=='+')    turn_F();
139                 else   {
140                     turn_F();turn_F();turn_F();
141                 }
142             }
143             else if(order[0]=='B'){
144                 if(order[1]=='+')    turn_B();
145                 else   {
146                     turn_B();turn_B();turn_B();
147                 }
148             }
149             else if(order[0]=='L'){
150                 if(order[1]=='+')    turn_L();
151                 else   {
152                     turn_L();
153                     turn_L();
154                     turn_L();
155                 }
156             }
157             else if(order[0]=='R'){
158                 if(order[1]=='+')    turn_R();
159                 else   {
160                     turn_R();turn_R();turn_R();
161                 }
162             }
163         }
164         for(i=1;i<10;++i){
165             cout<<T[i];
166             if(i%3==0) cout<<endl;
167         }
168         }
169     }
170     return 0;
171 }

 

 

 

posted on 2013-07-22 12:18 symons 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/symons1992/p/3205077.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值