Defuse the Bomb-大模拟

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

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!


Author: JIANG, Kai
Source: The 13th Zhejiang Provincial Collegiate Programming Contest
思路:4*5个if用两个数组存答案模拟每一步

代码如下:

#include<iostream> 
#include<cstring>
#include<cstdio>
using namespace std;
int biaoqian[1009],weizhi[1009],pingmu[10009];//把每步答案存数组用于调用
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		int xian;
		while(n--)
		{
			int anwz,weizh;
			memset(biaoqian,0,sizeof(biaoqian));
			memset(weizhi,0,sizeof(weizhi));
			memset(pingmu,0,sizeof(pingmu));//初始化
			for(int i=1;i<=5;++i)
			{
				scanf("%d",&xian);
				for(int j=1;j<=4;++j)
				{
					scanf("%d",&pingmu[j]);
				}
				if(xian == 1)
				{
					if(i == 1)
					{
						anwz = pingmu[2];
						biaoqian[i] = anwz;
						weizhi[i] = 2;weizh = weizhi[i] ;
					}
					if(i == 2)
					{
						anwz = 4;biaoqian[i] = anwz;
						for(int z=1;z<=4;++z)
						{
							if(pingmu[z] == 4)
							{
								weizhi[i] = z;break;
							}
						}weizh = weizhi[i] ;	
					}
					if(i == 3)
					{
						anwz = biaoqian[2];
						biaoqian[i] = anwz;
						for(int z=1;z<=4;++z)
						{
							if(pingmu[z] == anwz)
							{
								weizhi[i] = z;break;
							}
						}weizh = weizhi[i] ;
					}
					if(i == 4)
					{
						anwz = pingmu[weizhi[1]];
						biaoqian[i] = anwz;
						weizhi[i] = weizhi[1];weizh = weizhi[i] ;	
					}
					if(i == 5)
					{
						anwz = biaoqian[1];
						biaoqian[i] = anwz;
						for(int z=1;z<=4;++z)
						{
							if(pingmu[z] == anwz)
							{
								weizhi[i] = z;break;
							}
						}weizh = weizhi[i] ;
					}
				}
				if(xian == 2)
				{
					if(i == 1)
					{
						anwz = pingmu[2];
						biaoqian[i] = anwz;
						weizhi[i] = 2;weizh = weizhi[i] ;
					}
					if(i == 2)
					{
						anwz = pingmu[weizhi[1]];
						biaoqian[i] = anwz;
						weizhi[i] = weizhi[1];weizh = weizhi[i] ;
					}
					if(i == 3)
					{
						anwz = biaoqian[1];
						biaoqian[i] = anwz;
						for(int z=1;z<=4;++z)
						{
							if(pingmu[z] == anwz)
							{
								weizhi[i] = z;break;
							}
						}weizh = weizhi[i] ;
					}
					if(i == 4)
					{
						anwz = pingmu[1];
						biaoqian[i] = anwz;
						weizhi[i] = 1;weizh = weizhi[i] ;
					}
					if(i == 5)
					{
						anwz = biaoqian[2];
						biaoqian[i] = anwz;
						for(int z=1;z<=4;++z)
						{
							if(pingmu[z] == anwz)
							{
								weizhi[i] = z;break;
							}
						}weizh = weizhi[i] ;
					}
				}
				if(xian == 3)
				{
					if(i == 1)
					{
						anwz = pingmu[3];
						biaoqian[i] = anwz;
						weizhi[i] = 3;weizh = weizhi[i] ;
					}
					if(i == 2)
					{
						anwz = pingmu[1];
						biaoqian[i] = anwz;
						weizhi[i] = 1;weizh = weizhi[i] ; 
					}
					if(i == 3)
					{
						anwz = pingmu[3];
						biaoqian[i] = anwz;
						weizhi[i] = 3;weizh = weizhi[i] ;
					}
					if(i == 4)
					{
						anwz = pingmu[weizhi[2]];
						biaoqian[i] = anwz;
						weizhi[i] = weizhi[2];weizh = weizhi[i] ;
					}
					if(i == 5)
					{
						anwz = biaoqian[4];
						biaoqian[i] = anwz;
						for(int z=1;z<=4;++z)
						{
							if(pingmu[z] == anwz)
							{
								weizhi[i] = z;break;
							}
						}weizh = weizhi[i] ;
					}
				}
				if(xian == 4)
				{
					if(i == 1)
					{
						anwz = pingmu[4];
						biaoqian[i] = anwz;
						weizhi[i] = 4;weizh = weizhi[i] ;
					}
					if(i == 2)
					{
						anwz = pingmu[weizhi[1]];
						biaoqian[i] = anwz;
						weizhi[i] = weizhi[1];weizh = weizhi[i] ;
					}
					if(i == 3)
					{
						anwz = 4;biaoqian[i] = anwz;
						for(int z=1;z<=4;++z)
						{
							if(pingmu[z] == 4)
							{
								weizhi[i] = z;
							}
						}weizh = weizhi[i] ;
					}
					if(i == 4)
					{
						anwz = pingmu[weizhi[2]];
						biaoqian[i] = anwz;
						weizhi[i] = weizhi[2];weizh = weizhi[i] ;
					}
					if(i == 5)
					{
						anwz = biaoqian[3];
						biaoqian[i] = anwz;
						for(int z=1;z<=4;++z)
						{
							if(pingmu[z] == anwz)
							{
								weizhi[i] = z;break;
							}
						}weizh = weizhi[i] ;
					}
				}//模拟每步
				printf("%d %d\n",weizh,anwz);//输出
			}
			
		}
			
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

-lyslyslys

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值