码迷,mamicode.com
首页 > 其他好文 > 详细

Defuse the Bomb——ZOJ3938模拟

时间:2016-05-13 01:03:53      阅读:404      评论:0      收藏:0      [点我收藏+]

标签:

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 DB1B2B3B4 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<cstdio>
using namespace std;

int status[6][2];
int pos[6][4];
int dis[6];
int lable[6][4];
void solve()
{
    for(int i = 1; i <= 5; i++) {
        switch(i) {
        case 1: {
            switch(dis[i]) {
            case 1 : case 2:
                status[1][0] = 2;
                status[1][1] = lable[1][2];
                break;
            case 3:
                status[1][0] = 3;
                status[1][1] = lable[1][3];
                break;
            case 4:
                status[1][0] = 4;
                status[1][1] = lable[1][4];
                break;
            }
            break;
        }
        case 2: {
            switch(dis[i]) {
            case 1:
                status[2][0] = pos[2][4];
                status[2][1] = 4;
                break;
            case 2:
                status[2][0] = status[1][0];
                status[2][1] = lable[2][status[1][0]];
                break;
            case 3:
                status[2][0] = 1;
                status[2][1] = lable[2][1];
                break;
            case 4:
                status[2][0] = status[1][0];
                status[2][1] = lable[2][status[2][0]];
                break;
            }
            break;
        }
        case 3: {
            switch(dis[i]) {
            case 1:
                status[3][1] = status[2][1];
                status[3][0] = pos[3][status[3][1]];
                break;
            case 2:
                status[3][1] = status[1][1];
                status[3][0] = pos[3][status[3][1]];
                break;
            case 3:
                status[3][1] = lable[3][3];
                status[3][0] = 3;
                break;
            case 4:
                status[3][1] = 4;
                status[3][0] = pos[3][status[3][1]];
                break;
            }
            break;
        }
        case 4: {
            switch(dis[i]) {
            case 1:
                status[4][0] = status[1][0];
                status[4][1] = lable[4][status[4][0]];
                break;
            case 2:
                status[4][0] = 1;
                status[4][1] = lable[4][status[4][0]];
                break;
            case 3:case 4:
                status[4][0] = status[2][0];
                status[4][1] = lable[4][status[4][0]];
                break;
            }
            break;
        }
        case 5: {
            switch(dis[i]) {
            case 1:
                status[5][1] = status[1][1];
                status[5][0] = pos[5][status[5][1]];
                break;
            case 2:
                status[5][1] = status[2][1];
                status[5][0] = pos[5][status[5][1]];
                break;
            case 3:
                status[5][1] = status[4][1];
                status[5][0] = pos[5][status[5][1]];
                break;
            case 4:
                status[5][1] = status[3][1];
                status[5][0] = pos[5][status[5][1]];
                break;
            }
            break;
        }
        }
    }
}
int main()
{
    int t,d,b1,b2,b3,b4;
    scanf("%d",&t);
    while(t--) {
        for(int i = 1; i <= 5; i++) {
            scanf("%d%d%d%d%d",&dis[i],&lable[i][1],&lable[i][2],&lable[i][3],&lable[i][4]);
            for(int j = 1; j <= 4; j++) {
                pos[i][lable[i][j]] = j;
            }
        }
        solve();
        for(int j = 1;j <= 5;j++){
            printf("%d %d\n",status[j][0],status[j][1]);
        }
    }
    return 0;
}


Defuse the Bomb——ZOJ3938模拟

标签:

原文地址:http://blog.csdn.net/litter_limbo/article/details/51347253

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!