记录编号 |
42297 |
评测结果 |
AAAAAAAAAA |
题目名称 |
轮回游戏 |
最终得分 |
100 |
用户昵称 |
Truth.Cirno |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
2.017 s |
提交时间 |
2012-09-18 20:57:38 |
内存使用 |
1.94 MiB |
显示代码纯文本
#include <cstdio>
using namespace std;
struct rec
{
int a[24];
};
const int RUL[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 ans[100];
bool done;
rec change(rec a,int r)
{
int i,temp;
temp=a.a[RUL[r][0]];
for (i=0;i<6;i++)
a.a[RUL[r][i]]=a.a[RUL[r][i+1]];
a.a[RUL[r][6]]=temp;
return(a);
}
void dfs(rec a,int deep,int lim)
{
if (deep>lim)
return;
int i,c[4]={0},temp;
c[a.a[6]]++;
c[a.a[7]]++;
c[a.a[8]]++;
c[a.a[11]]++;
c[a.a[12]]++;
c[a.a[15]]++;
c[a.a[16]]++;
c[a.a[17]]++;
c[0]=c[1];
temp=1;
if (c[0]<c[2])
{
c[0]=c[2];
temp=2;
}
if (c[0]<c[3])
{
c[0]=c[3];
temp=3;
}
if (c[0]==8)
{
done=true;
if (deep==0)
{
printf("No moves needed");
printf("\n%d\n",temp);
return;
}
for (i=1;i<=deep;i++)
printf("%c",'A'+ans[i]);
printf("\n%d\n",temp);
return;
}
if (8-c[0]>lim-deep)
return;//short cut
for (i=0;i<8;i++)
{
ans[deep+1]=i;
dfs(change(a,i),deep+1,lim);
if (done)
return;
}
}
int main(void)
{
freopen("rotationa.in","r",stdin);
freopen("rotationa.out","w",stdout);
int i,lim;
rec a={0};
while (scanf("%d",&a.a[0]))
{
if (!a.a[0])
break;
for (i=1;i<24;i++)
scanf("%d",&a.a[i]);
done=false;
for (lim=1;!done;lim++)
dfs(a,0,lim);
}
return(0);
}