The 13th Zhejiang Provincial Collegiate Programming Contest-Defuse the Bomb(模拟)

来源:互联网 发布:积分入学社保怎么算法 编辑:程序博客网 时间:2024/04/30 16:48
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!


题目意思:

有四颗炸弹分别对应四个标签,序号都是1-4;

要用五个步骤才能拆除炸弹,分别是Stage 1-Stage 5

显示器上的数字N,对应Stage 中的display的数字;

求每一Stage 步骤中,拆除炸弹的标签位置及标签号。


解题思路:

Stage  一步步模拟就能水过了。。注意看清楚过程。。

/* * Copyright (c) 2016, 烟台大学计算机与控制工程学院 * All rights reserved. * 文件名称:bomb.cpp * 作    者:单昕昕 * 完成日期:2016年4月23日 * 版 本 号:v1.0 */  #include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;int a[4],b[4],s[5];int main(){    int t;    scanf("%d",&t);    while(t--)    {        memset(a,-1,sizeof(a));        memset(b,-1,sizeof(b));        int i;        for(i=0; i<5; ++i)        {            int n;            cin>>n;            for(int j=1; j<=4; ++j)                cin>>s[j];            if(i==0)            {                if(n==1||n==2)                {                    a[0]=2;                    b[0]=s[a[0]];                    printf("%d %d\n",a[0],b[0]);                }                else if(n==3)                {                    a[0]=3;                    b[0]=s[a[0]];                    printf("%d %d\n",a[0],b[0]);                }                else if(n==4)                {                    a[0]=4;                    b[0]=s[a[0]];                    printf("%d %d\n",a[0],b[0]);                }            }            else if(i==1)            {                if(n==1)                {                    for(int k=1; k<=4; ++k)                        if(s[k]==4)                        {                            a[1]=k;                            b[1]=s[a[1]];                            printf("%d %d\n",a[1],b[1]);                            break;                        }                }                else if(n==2||n==4)                {                    a[1]=a[0];                    b[1]=s[a[1]];                    printf("%d %d\n",a[1],b[1]);                }                else if(n==3)                {                    a[1]=1;                    b[1]=s[a[1]];                    printf("%d %d\n",a[1],b[1]);                }            }            else if(i==2)            {                if(n==1)                {                    b[2]=b[1];                    for(int k=1; k<=4; ++k)                        if(s[k]==b[2])                        {                            a[2]=k;                            break;                        }                    printf("%d %d\n",a[2],b[2]);                }                else if(n==2)                {                    b[2]=b[0];                    for(int k=1; k<=4; ++k)                        if(s[k]==b[2])                        {                            a[2]=k;                            break;                        }                    printf("%d %d\n",a[2],b[2]);                }                else if(n==3)                {                    a[2]=3;                    b[2]=s[a[2]];                    printf("%d %d\n",a[2],b[2]);                }                else if(n==4)                {                    for(int k=1; k<=4; ++k)                        if(s[k]==4)                        {                            a[2]=k;                            b[2]=s[a[2]];                            printf("%d %d\n",a[2],b[2]);                            break;                        }                }            }            else if(i==3)            {                if(n==1)                {                    a[3]=a[0];                    b[3]=s[a[3]];                    printf("%d %d\n",a[3],b[3]);                }                else if(n==2)                {                    a[3]=1;                    b[3]=s[a[3]];                    printf("%d %d\n",a[3],b[3]);                }                else if(n==3||n==4)                {                    a[3]=a[1];                    b[3]=s[a[3]];                    printf("%d %d\n",a[3],b[3]);                }            }            else if(i==4)            {                if(n==1)                {                    b[4]=b[0];                    for(int k=1; k<=4; ++k)                        if(s[k]==b[4])                        {                            a[4]=k;                            break;                        }                    printf("%d %d\n",a[4],b[4]);                }                else if(n==2)                {                    b[4]=b[1];                    for(int k=1; k<=4; ++k)                        if(s[k]==b[4])                        {                            a[4]=k;                            break;                        }                    printf("%d %d\n",a[4],b[4]);                }                else if(n==3)                {                    b[4]=b[3];                    for(int k=1; k<=4; ++k)                        if(s[k]==b[4])                        {                            a[4]=k;                            break;                        }                    printf("%d %d\n",a[4],b[4]);                }                else if(n==4)                {                    b[4]=b[2];                    for(int k=1; k<=4; ++k)                        if(s[k]==b[4])                        {                            a[4]=k;                            break;                        }                    printf("%d %d\n",a[4],b[4]);                }            }        }    }    return 0;}


0 0
原创粉丝点击