The 13th Zhejiang Provincial Collegiate Programming Contest

Defuse the Bomb

Time Limit: 2 Seconds      Memory Limit: 65536 KB

The bomb is about to explode! Please defuse it as soon as possible!

There is a display showing a number from 1 to 4 on the bomb. Besides this, there are 4 buttons under the display. Each button is labeled by a number from 1 to 4. The numbers on the buttons are always distinct.

There are 5 defusing stages in total. Pressing the correct button can progress the bomb to the next defusing stage. The number on the display and the number on each button may be different in different stages. The bomb will be defused only when all 5 defusing stages get passed. Pressing the incorrect button will cause the bomb to explode immediately. Be careful!

Here is the detailed bomb defusing manual. Button positions are ordered from left to right.

Stage 1:

  • If the display is 1, press the button in the second position.
  • If the display is 2, press the button in the second position.
  • If the display is 3, press the button in the third position.
  • If the display is 4, press the button in the fourth position.

Stage 2:

  • If the display is 1, press the button labeled "4".
  • If the display is 2, press the button in the same position as you pressed in stage 1.
  • If the display is 3, press the button in the first position.
  • If the display is 4, press the button in the same position as you pressed in stage 1.

Stage 3:

  • If the display is 1, press the button with the same label you pressed in stage 2.
  • If the display is 2, press the button with the same label you pressed in stage 1.
  • If the display is 3, press the button in the third position.
  • If the display is 4, press the button labeled "4".

Stage 4:

  • If the display is 1, press the button in the same position as you pressed in stage 1.
  • If the display is 2, press the button in the first position.
  • If the display is 3, press the button in the same position as you pressed in stage 2.
  • If the display is 4, press the button in the same position as you pressed in stage 2.

Stage 5:

  • If the display is 1, press the button with the same label you pressed in stage 1.
  • If the display is 2, press the button with the same label you pressed in stage 2.
  • If the display is 3, press the button with the same label you pressed in stage 4.
  • If the display is 4, press the button with the same label you pressed in stage 3.

Input

There are multiple test cases. The first line of input is an integer T indicating the number of test cases. For each test case:

There are 5 lines. Each line contains 5 integers D, B1, B2, B3, B4 indicating the number on the display and the numbers on the buttons respectively. The i-th line correspond to the i-th stage.

Output

For each test case, output 5 lines. The i-th line contains two integers indicating the position and the label of the correct button for the i-th stage.

Sample Input

1
4 2 1 3 4
2 2 4 3 1
4 3 1 4 2
4 3 4 2 1
2 3 1 2 4

Sample Output

4 4
4 1
3 4
4 1
2 1

Hint

Keep talking with your teammates and nobody explodes!

题意:拆炸弹 5个阶段 根据显示的不同  按不同的键

题解:恶心模拟

  1  #include<iostream>
  2  #include<cstring>
  3  #include<cstdio>
  4  #include<queue>
  5  #include<stack>
  6  #include<map>
  7  #include<set>
  8  #include<algorithm>
  9  #define LL __int64
 10  #define pi acos(-1.0)
 11  #define mod 1
 12  #define maxn 10000
 13  using namespace std;
 14  int t;
 15  int d1,d2,d3,d4,d5;
 16  int b1[5];
 17  int b2[5];
 18  int b3[5];
 19  int b4[5];
 20  int b5[5];
 21  int main()
 22  {
 23      while(scanf("%d",&t)!=EOF)
 24      {
 25          for(int i=1;i<=t;i++)
 26          {
 27              int x1,y1;
 28              int x2,y2;
 29              int x3,y3;
 30              int x4,y4;
 31              int x5,y5;
 32              scanf("%d %d %d %d %d",&d1,&b1[1],&b1[2],&b1[3],&b1[4]);
 33              if(d1==1||d1==2)
 34              {
 35                  x1=2;
 36                  y1=b1[2];
 37             }
 38              else
 39              if(d1==3)
 40              {
 41                  x1=3;
 42                  y1=b1[3];
 43              }
 44              else
 45              if(d1==4)
 46              {  x1=4;
 47                  y1=b1[4];
 48              }
 49              cout<<x1<<" "<<y1<<endl; 
 50              scanf("%d %d %d %d %d",&d2,&b2[1],&b2[2],&b2[3],&b2[4]);
 51              if(d2==2||d2==4)
 52                {
 53                    x2=x1;
 54                    y2=b2[x1];    
 55               }
 56               else
 57               if(d2==3)
 58                 {
 59                     x2=1;
 60                     y2=b2[1];
 61                 }
 62                 else
 63                 if(d2==1)
 64                 {   int k;
 65                     for(k=1;k<=4;k++)
 66                      if(b2[k]==4)
 67                      break;
 68                     x2=k;
 69                     y2=4;
 70                 }
 71             cout<<x2<<" "<<y2<<endl;
 72              scanf("%d %d %d %d %d",&d3,&b3[1],&b3[2],&b3[3],&b3[4]);
 73              if(d3==1)
 74              {
 75              int k;
 76               for(k=1;k<=4;k++)
 77               if(b3[k]==y2)
 78                      break;
 79                 x3=k;
 80                 y3=y2;    
 81              }
 82              else
 83              if(d3==2)
 84              {
 85                   int k;
 86               for(k=1;k<=4;k++)
 87              if(b3[k]==y1)
 88                      break;
 89                 x3=k;
 90                 y3=y1;    
 91              }
 92              else
 93              if(d3==3)
 94              {
 95                  x3=3;
 96                  y3=b3[3];
 97              }
 98              else
 99              if(d3==4)
100              {
101                  int k;
102                  for(k=1;k<=4;k++)
103                      if(b3[k]==4)
104                      break;
105                     x3=k;
106                     y3=4;
107              }
108              cout<<x3<<" "<<y3<<endl;
109              scanf("%d %d %d %d %d",&d4,&b4[1],&b4[2],&b4[3],&b4[4]);
110              if(d4==1)
111               {
112                  x4=x1;
113                  y4=b4[x1];
114              }
115              else
116              if(d4==2)
117              {
118                  x4=1;
119                  y4=b4[1];
120              }
121              else
122              if(d4==3)
123              {  x4=x2;
124                  y4=b4[x2];
125              }
126              else
127              if(d4==4)
128              {
129                  x4=x2;
130                  y4=b4[x2];
131              }
132              cout<<x4<<" "<<y4<<endl;
133              scanf("%d %d %d %d %d",&d5,&b5[1],&b5[2],&b5[3],&b5[4]);
134              if(d5==1)
135              {
136                  int k;
137                     for(k=1;k<=4;k++)
138                      if(b5[k]==y1)
139                      break;
140                     x5=k;
141                     y5=y1;
142              }
143              else
144              if(d5==2)
145              {
146                  int k;
147                     for(k=1;k<=4;k++)
148                      if(b5[k]==y2)
149                      break;
150                     x5=k;
151                     y5=y2;
152              }
153              else
154              if(d5==3)
155              {
156                  int k;
157                     for(k=1;k<=4;k++)
158                      if(b5[k]==y4)
159                      break;
160                     x5=k;
161                     y5=y4;
162              }
163              else
164              if(d5==4)
165              {
166                  int k;
167                     for(k=1;k<=4;k++)
168                      if(b5[k]==y3)
169                      break;
170                     x5=k;
171                     y5=y3;
172              }
173              cout<<x5<<" "<<y5<<endl;
174          }
175     }
176      return 0;
177  }
原文地址:https://www.cnblogs.com/hsd-/p/5424991.html