C - Defuse the Bomb

本文提供了一个详细的炸弹拆解手册,包括五个阶段的操作流程。通过分析显示的数字和按钮标签,指导如何正确按下按钮以顺利进行到下一阶段,直至完全拆解炸弹。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

<h4< dd="">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.

<h4< dd="">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
<h4< dd="">Sample Output
4 4
4 1
3 4
4 1
2 1
<h4< dd="">Hint

Keep talking with your teammates and nobody explodes!



这是一道模拟题,跟着题目往下写就好了,思路就是用结构体来存每个阶段按的位置和按的按钮的数字,然后模拟每个过程就好了

#include <bits/stdc++.h>

using namespace std;
int th[10][10];
struct node{
int wei;
int val;
}ch[10];
int Find(int h, int val)
{
    for(int i = 1; i < 5; i ++){
        if(th[h][i] == val) return i;
    }
}
int main()
{
    int num;
    scanf("%d", &num);
    while(num --){
        for(int i = 0; i < 5; i ++){
            for(int j = 0; j < 5; j ++){
              scanf("%d", &th[i][j]);
            }
        }
        for(int i = 0; i < 5; i ++){
            if(i == 0 && th[i][0] == 1){
                ch[i].wei = 2;
                ch[i].val  = th[i][2];
            }else if(i == 0 && th[i][0] == 2){
                ch[i].wei = 2;
                ch[i].val  = th[i][2];
            }else if(i == 0 && th[i][0] == 3){
                ch[i].wei = 3;
                ch[i].val  = th[i][3];
            }else if(i == 0 && th[i][0] == 4){
                ch[i].wei = 4;
                ch[i].val  = th[i][4];
            }else if(i == 1 && th[i][0] == 1){
                ch[i].wei = Find(1, 4);
                ch[i].val  = 4;
            }else if(i == 1 && th[i][0] == 2){
                ch[i].wei = ch[0].wei;
                ch[i].val  = th[i][ch[0].wei];
            }else if(i == 1 && th[i][0] == 3){
                ch[i].wei = 1;
                ch[i].val  = th[i][1];
            }else if(i == 1 && th[i][0] == 4){
                ch[i].wei = ch[0].wei;
                ch[i].val  = th[i][ch[0].wei];
            }else if(i == 2 && th[i][0] == 1){
                ch[i].wei = Find(2, ch[1].val);
                ch[i].val  = ch[1].val;
            }else if(i == 2 && th[i][0] == 2){
                ch[i].wei = Find(2, ch[0].val);
                ch[i].val = ch[0].val;
            }else if(i == 2 && th[i][0] == 3){
                ch[i].wei = 3;
                ch[i].val = th[i][3];
            }else if(i == 2 && th[i][0] == 4){
                ch[i].wei = Find(2, 4);
                ch[i].val  = 4;
            }else if(i == 3 && th[i][0] == 1){
                ch[i].wei = ch[0].wei;
                ch[i].val  = th[i][ch[0].wei];
            }else if(i == 3 && th[i][0] == 2){
                ch[i].wei = 1;
                ch[i].val  = th[i][1];
            }else if(i == 3 && th[i][0] == 3){
                ch[i].wei = ch[1].wei;
                ch[i].val  = th[i][ch[1].wei];
            }else if(i == 3 && th[i][0] == 4){
                ch[i].wei = ch[1].wei;
                ch[i].val  = th[i][ch[1].wei];
            }else if(i == 4 && th[i][0] == 1){
                ch[i].wei = Find(i, ch[0].val);
                ch[i].val  = ch[0].val;
            }else if(i == 4 && th[i][0] == 2){
                ch[i].wei = Find(i, ch[1].val);
                ch[i].val  = ch[1].val;
            }else if(i == 4 && th[i][0] == 3){
                ch[i].wei = Find(i, ch[3].val);
                ch[i].val  = ch[3].val;
            }else if(i == 4 && th[i][0] == 4){
                ch[i].wei = Find(i, ch[2].val);
                ch[i].val  = ch[2].val;
            }
        }
        for(int i = 0; i < 5; i ++){
            cout << ch[i].wei << " " << ch[i].val << endl;
        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值