• HDOJ Another Eight Puzzle


    根据题目描述,可以知道 1 和 8 只能放在 C 和 F 两个位置,固定好 1 和 8 后,2 和 7 也就固定了,剩下的就是枚举了;

    View Code
    # include <cstdio>
    
    const int tab[][8] = { {7, 3, 1, 4, 5, 8, 6, 2},
                           {7, 4, 1, 3, 6, 8, 5, 2},
                           {2, 5, 8, 6, 3, 1, 4, 7},
                           {2, 6, 8, 5, 4, 1, 3, 7}};
    
    int a[9];
    
    void solve(void)
    {
        int ans, cnt, i, j;
    
        for (i = 0; i < 8; ++i)
            scanf("%d", &a[i]);
        ans = -1, cnt = 0;
        for (j = 0; j < 4; ++j)
        {
            for (i = 0; i < 8; ++i)
                if (a[i] && a[i]!=tab[j][i]) break;
            if(i == 8) {++cnt;ans = j;}
        }
        if (cnt == 0) puts(" No answer");
        else if (cnt > 1) puts(" Not unique");
        else
        {
            for (int i = 0; i < 8; ++i)
                printf(" %d", tab[ans][i]);
            putchar('\n');
        }
    }
    
    int main()
    {
        int T;
    
        scanf("%d", &T);
        for (int i = 1; i <= T; ++i)
        {
            printf("Case %d:", i);
            solve();
        }
    
        return 0;
    }

    /**/

  • 相关阅读:
    Django系列:TemplateView,ListView,DetailView
    Django系列:开发自己的RestAPI
    Django系列:Restful CBV
    Django系列:RestFul
    Django系列12:Django模型关系
    B
    All about that base
    Safe Passage
    A
    Isomorphic Inversion
  • 原文地址:https://www.cnblogs.com/JMDWQ/p/2601415.html
Copyright © 2020-2023  润新知