ZOJ 3938 Defuse the Bomb(水题)

来源:互联网 发布:手机淘宝评论怎么截图 编辑:程序博客网 时间:2024/06/18 13:57


Defuse the Bomb


Description

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

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!




这题只要读懂题目,进行一个标记,那么就没有问题了,

题目大意:

有一个炸弹,现在要求你按照规则按下按钮,每一个按下的规则都不一样,Stage 1:    Stage 2 :     Stage 3:   Stage 4:       Stage 5:这么长的介绍就是介绍的规则,有的说是要求按下几号按键,有的说是要求按下上面数字 为 某个数的按钮,还有说是跟某一组的按下的标签一样的,有的是说按下和某组按下的数值一样的,所以只要做好标记的行了,一个水题



附上代码:

#include<cstdio>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>#include<string>#define INF 0x3f3f3f3f#define PI 3.1417using namespace std;int main(){int d[6][5] = {{0,0,0,0,0},{0,2,2,3,4},{0,-4,11,1,11},{0,-12,-11,3,-4},{0,11,1,12,12},{0,-11,-12,-14,-13}}; int t;cin >> t;while(t--){int sum[6][2] = {0};for(int i = 1;i <= 5;i++){int a[5] = {0};cin >> a[0];for(int j = 1;j <= 4;j++){cin >> a[j]; }if(d[i][a[0]] < 0 && d[i][a[0]] > -10)            //  标记大于 -10 小于 0 的   说明是要按下按钮上的数值为  a[0]  的{for(int j = 1;j <= 4;j++){if(a[j] == -d[i][a[0]]){sum[i][0] = j;sum[i][1] = a[sum[i][0]];break;}}}else if(d[i][a[0]] > 10)                          {sum[i][0] = sum[d[i][a[0]] % 10][0];sum[i][1] = a[sum[i][0]];}else if(d[i][a[0]] > 0 && d[i][a[0]] < 10){sum[i][0] = d[i][a[0]];sum[i][1] = a[sum[i][0]];}else{sum[i][1] = sum[(d[i][a[0]] * -1) % 10][1];for(int j = 1;j <= 4;j++){if(a[j] == sum[i][1]){sum[i][0] = j;break;}}}}for(int i = 1;i <= 5;i++){cout << sum[i][0] << " " << sum[i][1] << endl;}}return 0;}



0 0
原创粉丝点击