您的位置:首页 > 其它

The 13th Zhejiang Provincial Collegiate Programming Contest - C

2016-04-23 16:50 579 查看
Defuse the BombTime Limit: 2 Seconds Memory Limit: 65536 KB
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!

题意:拆炸弹 5个阶段 根据显示的不同 按不同的键

题解:恶心模拟

#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#define LL __int64
#define pi acos(-1.0)
#define mod 1
#define maxn 10000
using namespace std;
int t;
int d1,d2,d3,d4,d5;
int b1[5];
int b2[5];
int b3[5];
int b4[5];
int b5[5];
int main()
{
while(scanf("%d",&t)!=EOF)
{
for(int i=1;i<=t;i++)
{
int x1,y1;
int x2,y2;
int x3,y3;
int x4,y4;
int x5,y5;
scanf("%d %d %d %d %d",&d1,&b1[1],&b1[2],&b1[3],&b1[4]);
if(d1==1||d1==2)
{
x1=2;
y1=b1[2];
}
else
if(d1==3)
{
x1=3;
y1=b1[3];
}
else
if(d1==4)
{  x1=4;
y1=b1[4];
}
cout<<x1<<" "<<y1<<endl;
scanf("%d %d %d %d %d",&d2,&b2[1],&b2[2],&b2[3],&b2[4]);
if(d2==2||d2==4)
{
x2=x1;
y2=b2[x1];
}
else
if(d2==3)
{
x2=1;
y2=b2[1];
}
else
if(d2==1)
{   int k;
for(k=1;k<=4;k++)
if(b2[k]==4)
break;
x2=k;
y2=4;
}
cout<<x2<<" "<<y2<<endl;
scanf("%d %d %d %d %d",&d3,&b3[1],&b3[2],&b3[3],&b3[4]);
if(d3==1)
{
int k;
for(k=1;k<=4;k++)
if(b3[k]==y2)
break;
x3=k;
y3=y2;
}
else
if(d3==2)
{
int k;
for(k=1;k<=4;k++)
if(b3[k]==y1)
break;
x3=k;
y3=y1;
}
else
if(d3==3)
{
x3=3;
y3=b3[3];
}
else
if(d3==4)
{
int k;
for(k=1;k<=4;k++)
if(b3[k]==4)
break;
x3=k;
y3=4;
}
cout<<x3<<" "<<y3<<endl;
scanf("%d %d %d %d %d",&d4,&b4[1],&b4[2],&b4[3],&b4[4]);
if(d4==1)
{
x4=x1;
y4=b4[x1];
}
else
if(d4==2)
{
x4=1;
y4=b4[1];
}
else
if(d4==3)
{  x4=x2;
y4=b4[x2];
}
else
if(d4==4)
{
x4=x2;
y4=b4[x2];
}
cout<<x4<<" "<<y4<<endl;
scanf("%d %d %d %d %d",&d5,&b5[1],&b5[2],&b5[3],&b5[4]);
if(d5==1)
{
int k;
for(k=1;k<=4;k++)
if(b5[k]==y1)
break;
x5=k;
y5=y1;
}
else
if(d5==2)
{
int k;
for(k=1;k<=4;k++)
if(b5[k]==y2)
break;
x5=k;
y5=y2;
}
else
if(d5==3)
{
int k;
for(k=1;k<=4;k++)
if(b5[k]==y4)
break;
x5=k;
y5=y4;
}
else
if(d5==4)
{
int k;
for(k=1;k<=4;k++)
if(b5[k]==y3)
break;
x5=k;
y5=y3;
}
cout<<x5<<" "<<y5<<endl;
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: