比赛 |
20120914 |
评测结果 |
TTTTTTTTTT |
题目名称 |
轮回游戏 |
最终得分 |
0 |
用户昵称 |
苏轼 |
运行时间 |
10.000 s |
代码语言 |
C++ |
内存使用 |
0.31 MiB |
提交时间 |
2012-09-14 21:57:08 |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
int q[24];
int w[20],biao;
int answer=0;
void dfs(int x);
int f[8][7]={{0,2,6,11,15,20,22},{1,3,8,12,17,21,23},{10,9,8,7,6,5,4},{19,18,17,16,15,14,13},{23,21,17,12,8,3,1},{22,20,15,11,6,2,0},{13,14,15,16,17,18,19},{4,5,6,7,8,9,10}};
int main()
{
freopen ("rotationa.in","r",stdin);
freopen ("rotationa.out","w",stdout);
while (1)
{
for (int i=0;i<24;i++)
{
cin>>q[i];
if (q[i]==0)
exit(0);
}
answer=0;
for (int i=1;i<12;i++)
{
biao=i;
dfs(0);
if (answer)
break;
}
if (answer==0)
cout<<"No moves needed"<<endl;
}
return 0;
}
void dfs(int x)
{
if (x>biao)
return;
if (answer)
return;
int c;
c=q[6];
if (c==q[7]&&c==q[8]&&c==q[11]&&c==q[12]&&c==q[15]&&c==q[16]&&c==q[17])
{
for (int i=0;i<x;i++)
{
char b;
b='A';
b+=w[i];
cout<<b;
}
cout<<endl<<c<<endl;
answer=1;
}
else
{
for (int i=0;i<8;i++)
{
w[x]=i;
int a;
a=q[f[i][0]];
for (int j=0;j<6;j++)
{
q[f[i][j]]=q[f[i][j+1]];
}
q[f[i][6]]=a;
x++;
dfs(x);
x--;
a=q[f[i][6]];
for (int j=6;j>0;j--)
{
q[f[i][j]]=q[f[i][j-1]];
}
q[f[i][0]]=a;
}
}
}