zoj Defuse the Bomb (模拟)

来源:互联网 发布:淘宝店怎么管理 编辑:程序博客网 时间:2024/06/05 02:16
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. Thei-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 thei-th stage.

Sample Input

14 2 1 3 42 2 4 3 14 3 1 4 24 3 4 2 12 3 1 2 4

Sample Output

4 44 13 44 12 1

Hint

Keep talking with your teammates and nobody explodes!

#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>using namespace std;struct zz{int e;int a,b,c,d;}p[10];struct ss{int p,a;}q[10];int a[10][10];int b[10][10];int main(){int t,i,j,k;scanf("%d",&t);while(t--){memset(a,0,sizeof(a));memset(b,0,sizeof(b));for(i=1;i<=5;i++){scanf("%d%d%d%d%d",&p[i].e,&p[i].a,&p[i].b,&p[i].c,&p[i].d);a[i][p[i].a]=1;a[i][p[i].b]=2;a[i][p[i].c]=3;a[i][p[i].d]=4;b[i][1]=p[i].a;b[i][2]=p[i].b;b[i][3]=p[i].c;b[i][4]=p[i].d;}for(i=1;i<=5;i++){if(i==1){if(p[1].e==1){q[1].p=2;q[1].a=p[1].b;}else if(p[1].e==2){q[1].p=2;q[1].a=p[1].b;}else if(p[1].e==3){q[1].p=3;q[1].a=p[1].c;}else if(p[1].e==4){q[1].p=4;q[1].a=p[1].d;}}else if(i==2){if(p[2].e==1){q[2].a=4;q[2].p=a[2][4];}else if(p[2].e==2){q[2].p=q[1].p;q[2].a=b[2][q[1].p];}else if(p[2].e==3){q[2].p=1;q[2].a=p[2].a;}else if(p[2].e==4){q[2].p=q[1].p;q[2].a=b[2][q[1].p];}}else if(i==3){if(p[3].e==1){q[3].a=q[2].a;q[3].p=a[3][q[2].a];}else if(p[3].e==2){q[3].a=q[1].a;q[3].p=a[3][q[1].a];}else if(p[3].e==3){q[3].p=3;q[3].a=p[3].c;}else if(p[3].e==4){q[3].a=4;q[3].p=a[3][4];}}else if(i==4){if(p[4].e==1){q[4].p=q[1].p;q[4].a=b[4][q[1].p];}else if(p[4].e==2){q[4].p=1;q[4].a=p[4].a;}else if(p[4].e==3){q[4].p=q[2].p;q[4].a=b[4][q[2].p];}else if(p[4].e==4){q[4].p=q[2].p;q[4].a=b[4][q[2].p];}}else if(i==5){if(p[5].e==1){q[5].a=q[1].a;q[5].p=a[5][q[1].a];}else if(p[5].e==2){q[5].a=q[2].a;q[5].p=a[5][q[2].a];}else if(p[5].e==3){q[5].a=q[4].a;q[5].p=a[5][q[4].a];}else if(p[5].e==4){q[5].a=q[3].a;q[5].p=a[5][q[3].a];}}}for(i=1;i<=5;i++)printf("%d %d\n",q[i].p,q[i].a);}return 0;}


 

0 0
原创粉丝点击