浙江省赛 Defuse the Bomb

题目:

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.

浙江省赛 Defuse the Bomb_第1张图片

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!


一道纯粹的模拟题,他说什么就写什么,但是条件太多了。。。做这道题的感觉就是一万个草泥马在心中奔驰而过。。。
 
 
下面是代码:
#include <iostream>
#include <string>
#include<stdio.h>
#include<malloc.h>
using namespace std;
#define MAX_N 50000
int a[7],b[7],c[7],d[7];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
            for(int i=1; i<=5; i++)
            {
                scanf("%d",&b[i]);
                for(int j=1; j<=4; j++)
                {
                    scanf("%d",&a[j]);
                }
                if(i==1)
                {
                    if(b[i]==1||b[i]==2)
                    {
                        printf("2 %d\n",a[2]);
                        c[i]=2;
                        d[i]=a[2];
                    }
                    if(b[i]==3)
                    {
                        printf("3 %d\n",a[3]);
                        c[i]=3;
                        d[i]=a[3];
                    }
                    if(b[i]==4)
                    {
                        printf("4 %d\n",a[4]);
                        c[i]=4;
                        d[i]=a[4];
                    }
                }
                else if(i==2)
                {
                    if(b[i]==1)
                    {
                        int k;
                        for( k=1; k<=4; k++)
                        {
                            if(a[k]==4)
                                break;
                        }
                        printf("%d 4\n",k);
                        c[i]=k;
                        d[i]=4;
                    }
                    if(b[i]==2||b[i]==4)
                    {
                        printf("%d %d\n",c[1],a[c[1]]);
                        c[i]=c[1];
                        d[i]=a[c[1]];
                    }
                    if(b[i]==3)
                    {
                        printf("1 %d\n",a[1]);
                        c[i]=1;
                        d[i]=a[1];
                    }
                }
                else if(i==3)
                {
                    if(b[i]==1)
                    {
                        int k;
                        for( k=1; k<=4; k++)
                        {
                            if(a[k]==d[2])
                                break;
                        }
                        printf("%d %d\n",k,d[2]);
                        c[i]=k;
                        d[i]=d[2];
                    }
                    if(b[i]==2)
                    {
                        int k;
                        for( k=1; k<=4; k++)
                        {
                            if(a[k]==d[1])
                                break;
                        }
                        printf("%d %d\n",k,d[1]);
                        c[i]=k;
                        d[i]=d[1];
                    }
                    if(b[i]==3)
                    {
                        printf("3 %d\n",a[3]);
                        c[i]=3;
                        d[i]=a[3];
                    }
                    if(b[i]==4)
                    {
                        int k;
                        for( k=1; k<=4; k++)
                        {
                            if(a[k]==4)
                                break;
                        }
                        printf("%d 4\n",k);
                        c[i]=k;
                        d[i]=4;
                    }
                }
                else if(i==4)
                {
                    if(b[i]==1)
                    {
                        printf("%d %d\n",c[1],a[c[1]]);
                        c[i]=c[1];
                        d[i]=a[c[1]];
                    }
                    if(b[i]==2)
                    {
                        printf("1 %d\n",a[1]);
                        c[i]=1;
                        d[i]=a[1];
                    }
                    if(b[i]==3||b[i]==4)
                    {
                        printf("%d %d\n",c[2],a[c[2]]);
                        c[i]=c[2];
                        d[i]=a[c[2]];
                    }
                }
                else
                {
                    if(b[i]==1)
                    {
                        int k;
                        for( k=1; k<=4; k++)
                        {
                            if(a[k]==d[1])
                                break;
                        }
                        printf("%d %d\n",k,d[1]);
                        c[i]=k;
                        d[i]=d[1];
                    }
                    if(b[i]==2)
                    {
                        int k;
                        for( k=1; k<=4; k++)
                        {
                            if(a[k]==d[2])
                                break;
                        }
                        printf("%d %d\n",k,d[2]);
                        c[i]=k;
                        d[i]=d[2];
                    }
                    if(b[i]==3)
                    {
                        int k;
                        for( k=1; k<=4; k++)
                        {
                            if(a[k]==d[4])
                                break;
                        }
                        printf("%d %d\n",k,d[4]);
                        c[i]=k;
                        d[i]=d[4];
                    }
                    if(b[i]==4)
                    {
                        int k;
                        for( k=1; k<=4; k++)
                        {
                            if(a[k]==d[3])
                                break;
                        }
                        printf("%d %d\n",k,d[3]);
                        c[i]=k;
                        d[i]=d[3];
                    }
                }
            }
        }

return 0;
}



你可能感兴趣的:(浙江省赛模拟题)