zoj-3938-Defuse the Bomb
2016-04-24 21:07
302 查看
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:
Stage 2:
Stage 3:
Stage 4:
Stage 5:
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
模拟题,直接按题意模拟即可
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
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
模拟题,直接按题意模拟即可
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> using namespace std; int main() { int t; scanf("%d", &t); int cc[6][6]; int kk[6][6]; int s[6]; int l[6]; kk[1][1]=2;kk[2][1]=4;kk[3][1]=2;kk[4][1]=1;kk[5][1]=1; cc[1][1]=1;cc[2][1]=2;cc[3][1]=3;cc[4][1]=4;cc[5][1]=3; kk[1][2]=2;kk[2][2]=1;kk[3][2]=1;kk[4][2]=1;kk[5][2]=2; cc[1][2]=1;cc[2][2]=4;cc[3][2]=3;cc[4][2]=1;cc[5][2]=3; kk[1][3]=3;kk[2][3]=1;kk[3][3]=3;kk[4][3]=2;kk[5][3]=4; cc[1][3]=1;cc[2][3]=1;cc[3][3]=1;cc[4][3]=4;cc[5][3]=3; kk[1][4]=4;kk[2][4]=1;kk[3][4]=4;kk[4][4]=2;kk[5][4]=3; cc[1][4]=1;cc[2][4]=4;cc[3][4]=2;cc[4][4]=4;cc[5][4]=3; while (t--) { for (int i = 1; i <= 5; i++) { int b; scanf("%d", &b); int a[5]; for (int j = 1; j <= 4; j++) { scanf("%d", a+j); } if (cc[i][b] == 1) { s[i] = a[kk[i][b]]; l[i] = kk[i][b]; printf("%d %d\n", kk[i][b], a[kk[i][b]]); } else if (cc[i][b] == 2) { for (int k = 1; k <= 4; k++) { if (a[k] == 4) { l[i] = k; s[i] = a[k]; printf("%d %d\n", k, a[k]); } } } else if (cc[i][b] == 3) { for (int k = 1; k <= 4; k++) { if (a[k] == s[kk[i][b]]) { l[i] = k; s[i] = a[k]; printf("%d %d\n", k, a[k]); } } } else { l[i] = l[kk[i][b]]; s[i] = a[l[i]]; printf("%d %d\n", l[i], a[l[i]]); } } } return 0; }
相关文章推荐
- 20145120 《Java程序设计》第8周学习总结
- hdu1059 多重背包
- 练习二 1011 Oil Deposits
- Java 对象的多态性——必须画图理解
- 两种用自定义数据初始化Mat
- 112. Path Sum
- Spring总结4—对持久层的支持(附:事务管理)
- 心跳包机制
- 项目经验--来自远秋同学
- 20145320 《Java程序设计》第8周学习总结
- Linux中tail指令详解
- 20145109竺文君、20145106石晟荣 java实验三
- 构建自己的PHP框架--构建缓存组件(1)
- 读写锁
- 党课心得三(杂谈)
- Java 继承的一些重点
- Android获得应用包名
- Leetcode Power of Two 231
- LintCode: 两个链表的交叉
- Strng[]去重