Defuse the Bomb——ZOJ3938模拟

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;
}
时间: 2024-07-30 13:53:04

Defuse the Bomb——ZOJ3938模拟的相关文章

[HDOJ6144] Arithmetic of Bomb(模拟)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6144 XJB模拟一下就行,反正最多重复⑨次. 非要说用上什么数学原理的话,大概就是(a+b)%mod = (a%mod)+(b%mod)%mod,(a*b)%mod...吧 1 /* 2 ━━━━━┒ギリギリ♂ eye! 3 ┓┏┓┏┓┃キリキリ♂ mind! 4 ┛┗┛┗┛┃\○/ 5 ┓┏┓┏┓┃ / 6 ┛┗┛┗┛┃ノ) 7 ┓┏┓┏┓┃ 8 ┛┗┛┗┛┃ 9 ┓┏┓┏┓┃ 10 ┛┗┛┗┛┃

2016.4.23 浙江省赛题解

Apples and Ideas Time Limit: 2 Seconds      Memory Limit: 65536 KB "If you have an apple and I have an apple and we exchange these apples then you and I will still each have one apple. But if you have an idea and I have an idea and we exchange these

2016.4.23浙江省赛

A      Apples and Ideas Time Limit: 2 Seconds      Memory Limit: 65536 KB "If you have an apple and I have an apple and we exchange these apples then you and I will still each have one apple. But if you have an idea and I have an idea and we exchange

2017&quot;百度之星&quot;程序设计大赛 - 复赛1001&amp;&amp;HDU 6144 Arithmetic of Bomb【java大模拟】

Arithmetic of Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 129    Accepted Submission(s): 94 Problem Description 众所周知,度度熊非常喜欢数字. 它最近在学习小学算术,第一次发现这个世界上居然存在两位数,三位数……甚至N位数! 但是这回的算术题可并不简单,由于

【模拟】Codeforces 699B One Bomb

题目链接: http://codeforces.com/problemset/problem/699/B 题目大意: N*M的图,*代表墙.代表空地.问能否在任意位置(可以是墙上)放一枚炸弹(能炸所在行和列),把所有的墙都炸掉.输出答案(不唯一). 题目思路: [模拟] N2预处理出每一行能炸多少墙,每一列能炸多少墙.再N2枚举放炸弹的位置看能炸掉的墙数目是否等于总数.注意如果炸弹位置上有墙要-1. 1 // 2 //by coolxxx 3 ////<bits/stdc++.h> 4 #in

hdu 4930 Fighting the Landlords (模拟)

Fighting the Landlords Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 160    Accepted Submission(s): 52 Problem Description Fighting the Landlords is a card game which has been a heat for ye

HDU 4930 Fighting the Landlords(扯淡模拟题)

Fighting the Landlords 大意: 斗地主....   分别给出两把手牌,肯定都合法.每张牌大小顺序是Y (i.e. colored Joker) > X (i.e. Black & White Joker) > 2 > A (Ace) > K (King) > Q (Queen) > J (Jack) > T (10) > 9 > 8 > 7 > 6 > 5 > 4 > 3. 给你8种组合:1.

Box2D物理引擎模拟炸弹爆炸效果

今天咱们来模拟炸弹效果.于是问题一来了:"为什么要模仿这么暴力的效果呢?莫非几日不见,Yorhom人品煞变?" 其实玩过愤怒的小鸟的同学都应该对这种效果似曾相识,因为据非官方报道,第二厉害的小鸟--黑色鸟的特技就是自爆.问题二出现了:"那第一厉害的小鸟是哪一种呢?"据Yorhom我本人测试,那只红色大鸟应该是最厉害的,不过貌似没有特技?愤怒的小鸟这种肤浅的游戏,Y某我最擅长了,以后有时间会专门写写这个游戏的攻略.这两种鸟的靓照如下: 敷衍了问问题二的同学,问题三就来

CSAPP Lab2: Binary Bomb

著名的CSAPP实验:二进制炸弹 就是通过gdb和反汇编猜测程序意图,共有6关和一个隐藏关卡 只有输入正确的字符串才能过关,否则会程序会bomb终止运行 隐藏关卡需要输入特定字符串方会开启 实验材料下载地址:http://csapp.cs.cmu.edu/2e/labs.html 下面通关解法: 反汇编: objdump -d bomb > bomb_assembly_32.S Phase 1: 打开bomb_assembly_32.S,定位到<phase_1>函数,可以看到以下代码: