题目地址:http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5698
思路:模拟
AC代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
#include <cctype>
const int inf = 0x3f3f3f3f;//1061109567
typedef long long LL;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
int a[5];
struct node
{
int pos;
int label;
} lol[6];
void nowpos(int now,int loc)
{
lol[now].pos = loc;
lol[now].label = a[loc];
}
void samepos(int now,int pre)
{
lol[now].pos = lol[pre].pos;
lol[now].label = a[lol[now].pos];
}
void samelabel(int now,int pre)
{
lol[now].label = lol[pre].label;
int i;
for(i=1; i<=4; i++)
{
if(a[i] == lol[now].label)
break;
}
lol[now].pos = i;
}
void label4(int now)
{
int j;
for(j=1; j<=4; j++)
{
if(a[j] == 4)
break;
}
lol[now].pos = j;
lol[now].label = 4;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
for(int i=1; i<=5; i++)
{
int f;
scanf("%d%d%d%d%d",&f,&a[1],&a[2],&a[3],&a[4]);
if(i == 1)
{
if(f == 1 || f == 2)
nowpos(i,2);
else if(f == 3)
nowpos(i,3);
else if(f == 4)
nowpos(i,4);
}
else if(i == 2)
{
if(f == 1)
label4(i);
else if(f == 2 || f == 4)
samepos(i,1);
else if(f == 3)
nowpos(i,1);
}
else if(i == 3)
{
if(f == 1)
samelabel(3,2);
else if(f == 2)
samelabel(3,1);
else if(f == 3)
nowpos(i,3);
else if(f == 4)
label4(i);
}
else if(i == 4)
{
if(f == 1)
samepos(i,1);
else if(f == 2)
nowpos(i,1);
else if(f == 3)
samepos(i,2);
else if(f == 4)
samepos(i,2);
}
else if(i ==5)
{
if(f == 1)
samelabel(i,1);
else if(f == 2)
samelabel(i,2);
else if(f == 3)
samelabel(i,4);
else if(f == 4)
samelabel(i,3);
}
printf("%d %d\n",lol[i].pos,lol[i].label);
}
}
return 0;
}