记录编号 |
42259 |
评测结果 |
AAAAAAAAAA |
题目名称 |
轮回游戏 |
最终得分 |
100 |
用户昵称 |
Makazeu |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.700 s |
提交时间 |
2012-09-18 14:50:49 |
内存使用 |
0.29 MiB |
显示代码纯文本
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int MAXN=25;
int Move[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 Center[10]={6,7,8,11,12,15,16,17};
int deep;typedef int array[MAXN]; array qe;
inline int Max(int a,int b) {return a>b?a:b;}
inline int Max(int a,int b,int c) {return Max(Max(a,b),Max(b,c));}
int path[MAXN];
inline int check(array &k)
{
int sl[3]={0};
for(int i=0;i<8;i++)
sl[k[Center[i]]-1]++;
return 8-Max(sl[0],sl[1],sl[2]);
}
bool dfs(int k)
{
if(k>deep) return false;
for(int i=0;i<8;i++)
{
path[k]=i; int x=qe[Move[i][0]];
for(int j=0;j<6;j++) qe[Move[i][j]]=qe[Move[i][j+1]];
qe[Move[i][6]]=x; x=check(qe); if( !x || (x+k<deep&&dfs(k+1)) ) return 1;
x=qe[Move[i][6]]; for(int j=6;j>0;j--) qe[Move[i][j]]=qe[Move[i][j-1]]; qe[Move[i][0]]=x;
}
return 0;
}
int main()
{
freopen("rotationa.in","r",stdin);
freopen("rotationa.out","w",stdout);
while(19941011<19941114)
{
deep=0;
for(int i=0;i<24;i++)
{
scanf("%d",&qe[i]);
if(qe[i]==0) exit(0);
}
if(!check(qe))
{
printf("No moves needed\n%d\n", qe[6]);
continue;
}
while(!dfs(0)) deep++;
for(int i=0;i<deep;i++) printf("%c",'A'+path[i]);
printf("\n%d\n",qe[6]);
}
return 0;
}