ZOJ Problem Set - 3938 (模拟)
来源:互联网 发布:我爱你韩国知乎 编辑:程序博客网 时间:2024/06/07 01:24
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. 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
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!
题意:按要求要经过 5 个阶段,每个阶段会显示 1--4 中的一个数,且有 1--4 号按钮,
根据显示数的不同来决定按钮的不同,依次显示该按钮的位置和编号。
分析:直接模拟。
代码如下:
#include <iostream>#include <cstdio>#include <cstring>#include <queue>#include <map>#include <algorithm>using namespace std;#define inf 0x3f3f3f3fint label[5], b[5], p[5], pos[5] = { 0, 2, 2, 3, 4 };int main(){#ifdef OFFLINEfreopen("t.txt", "r", stdin);#endifint t, i, j, n, m, d, num;scanf("%d", &t);while (t--){map<int, int> map;for (i = 1; i <= 5; i++){scanf("%d%d%d%d%d", &d, &b[1], &b[2], &b[3], &b[4]);if (i == 2 || i == 3){if (b[1] == 4) p[i] = 1;else if (b[2] == 4) p[i] = 2;else if (b[3] == 4) p[i] = 3;else p[i] = 4;}if (i == 1){p[i] = pos[d];label[i] = b[pos[d]];}else{map[b[1]] = 1; map[b[2]] = 2;map[b[3]] = 3; map[b[4]] = 4;if (i == 2){if (d == 2) p[i] = p[1];else if (d == 3) p[i] = 1;else if(d==4) p[i] = p[1];}else if (i == 3){if (d == 1) p[i] = map[label[2]];else if (d == 2) p[i] = map[label[1]];else if (d == 3) p[i] = 3;}else if (i == 4){if (d == 1) p[i] = p[1];else if (d == 2) p[i] = 1;else p[i] = p[2];}else{if (d == 1) p[i] = map[label[1]];else if (d == 2) p[i] = map[label[2]];else if (d == 3) p[i] = map[label[4]];else p[i] = map[label[3]];} label[i] = b[p[i]];}printf("%d %d\n", p[i], label[i]);}}return 0;}
- ZOJ Problem Set - 3938 (模拟)
- 字符串的处理(模拟) ZOJ Problem Set - 1099 HTML
- ZOJ Problem Set - 2186 Keep on Truckin'【模拟】
- ZOJ Problem Set - 3490 String Successor(字符串模拟)
- ZOJ Problem Set - 3938 Defuse the Bomb
- ZOJ Problem Set - 2060
- ZOJ Problem Set - 2972
- ZOJ Problem Set - 1037
- ZOJ Problem Set - 1048
- ZOJ Problem Set - 1049
- ZOJ Problem Set - 1051
- ZOJ Problem Set - 1067
- ZOJ Problem Set - 1115
- ZOJ Problem Set - 1151
- ZOJ Problem Set - 1205
- ZOJ Problem Set - 1025
- ZOJ Problem Set - 1029
- ZOJ Problem Set - 1076
- Android Service
- Android UI优化之include标签的使用
- atexit()函数的使用
- Android多线程与线程池
- HDU 1219 AC Me(字母统计)
- ZOJ Problem Set - 3938 (模拟)
- SQL
- Linux文件与文件系统的压缩与打包
- C语言中.h和.c文件解析(很精彩)
- OC可变数组(NSMutableArray)相关方法
- Ajax和JSON
- LeetCode - Reverse Vowels of a String
- ArrayList、HashTable到JSON
- IOS-62-实现进程间、线程间通信的方式