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.
![](http://acm.zju.edu.cn/onlinejudge/showImage.do?name=zjcpc_bomb.png)
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
Keep talking with your teammates and nobody explodes!
题目意思:
有四颗炸弹分别对应四个标签,序号都是1-4;
要用五个步骤才能拆除炸弹,分别是Stage 1-Stage 5
显示器上的数字N,对应Stage 中的display的数字;
求每一Stage 步骤中,拆除炸弹的标签位置及标签号。
解题思路:
按Stage 一步步模拟就能水过了。。注意看清楚过程。。
/*
* Copyright (c) 2016, 烟台大学计算机与控制工程学院
* All rights reserved.
* 文件名称:bomb.cpp
* 作 者:单昕昕
* 完成日期:2016年4月23日
* 版 本 号:v1.0
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int a[4],b[4],s[5];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(a,-1,sizeof(a));
memset(b,-1,sizeof(b));
int i;
for(i=0; i<5; ++i)
{
int n;
cin>>n;
for(int j=1; j<=4; ++j)
cin>>s[j];
if(i==0)
{
if(n==1||n==2)
{
a[0]=2;
b[0]=s[a[0]];
printf("%d %d\n",a[0],b[0]);
}
else if(n==3)
{
a[0]=3;
b[0]=s[a[0]];
printf("%d %d\n",a[0],b[0]);
}
else if(n==4)
{
a[0]=4;
b[0]=s[a[0]];
printf("%d %d\n",a[0],b[0]);
}
}
else if(i==1)
{
if(n==1)
{
for(int k=1; k<=4; ++k)
if(s[k]==4)
{
a[1]=k;
b[1]=s[a[1]];
printf("%d %d\n",a[1],b[1]);
break;
}
}
else if(n==2||n==4)
{
a[1]=a[0];
b[1]=s[a[1]];
printf("%d %d\n",a[1],b[1]);
}
else if(n==3)
{
a[1]=1;
b[1]=s[a[1]];
printf("%d %d\n",a[1],b[1]);
}
}
else if(i==2)
{
if(n==1)
{
b[2]=b[1];
for(int k=1; k<=4; ++k)
if(s[k]==b[2])
{
a[2]=k;
break;
}
printf("%d %d\n",a[2],b[2]);
}
else if(n==2)
{
b[2]=b[0];
for(int k=1; k<=4; ++k)
if(s[k]==b[2])
{
a[2]=k;
break;
}
printf("%d %d\n",a[2],b[2]);
}
else if(n==3)
{
a[2]=3;
b[2]=s[a[2]];
printf("%d %d\n",a[2],b[2]);
}
else if(n==4)
{
for(int k=1; k<=4; ++k)
if(s[k]==4)
{
a[2]=k;
b[2]=s[a[2]];
printf("%d %d\n",a[2],b[2]);
break;
}
}
}
else if(i==3)
{
if(n==1)
{
a[3]=a[0];
b[3]=s[a[3]];
printf("%d %d\n",a[3],b[3]);
}
else if(n==2)
{
a[3]=1;
b[3]=s[a[3]];
printf("%d %d\n",a[3],b[3]);
}
else if(n==3||n==4)
{
a[3]=a[1];
b[3]=s[a[3]];
printf("%d %d\n",a[3],b[3]);
}
}
else if(i==4)
{
if(n==1)
{
b[4]=b[0];
for(int k=1; k<=4; ++k)
if(s[k]==b[4])
{
a[4]=k;
break;
}
printf("%d %d\n",a[4],b[4]);
}
else if(n==2)
{
b[4]=b[1];
for(int k=1; k<=4; ++k)
if(s[k]==b[4])
{
a[4]=k;
break;
}
printf("%d %d\n",a[4],b[4]);
}
else if(n==3)
{
b[4]=b[3];
for(int k=1; k<=4; ++k)
if(s[k]==b[4])
{
a[4]=k;
break;
}
printf("%d %d\n",a[4],b[4]);
}
else if(n==4)
{
b[4]=b[2];
for(int k=1; k<=4; ++k)
if(s[k]==b[4])
{
a[4]=k;
break;
}
printf("%d %d\n",a[4],b[4]);
}
}
}
}
return 0;
}