比赛 20120914 评测结果 AAAAAAAAAA
题目名称 轮回游戏 最终得分 100
用户昵称 王者自由 运行时间 0.743 s
代码语言 C++ 内存使用 0.30 MiB
提交时间 2012-09-14 19:43:44
显示代码纯文本
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 1000 + 10;
int G[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 u[8] = {6, 7, 8, 11, 12, 15, 16, 17};
int v[8] = {5, 4, 7, 6, 1, 0, 3, 2};
int w[N], d;
int s[32];
int Dis() {
    int a[3] = {0};
    for(int i=0; i<8; i++)
        a[s[u[i]] - 1]++;
    return 8 - max(max(a[0], a[1]), a[2]);
}
void Ext(int r) {
    int t = s[G[r][0]];
    for(int i=1; i<=6; i++)
        s[G[r][i-1]] = s[G[r][i]];
    s[G[r][6]] = t;
}
bool DFS(int p) {
    for(int i=0; i<8; i++) {
        Ext(w[p] = i);
        int t = Dis();
        if(!t || (t + p < d && DFS(p+1)))
            return 1;
        Ext(v[i]);
    } return 0;
}
int main() {
    freopen("rotationa.in", "r", stdin);
    freopen("rotationa.out", "w", stdout);
    while(scanf("%d", s), s[0]) {
        for(int i=1; i<24; i++)
            scanf("%d", s+i);
        if(!(d = Dis())) {
            printf("No moves needed\n%d\n", s[6]);
            continue;
        }
        while(!DFS(0)) d++;
        for(int i=0; i<d; i++)
            printf("%c", w[i]+'A');
        printf("\n%d\n", s[6]);
    }
    return 0;
}