zoukankan      html  css  js  c++  java
  • USACO sec1.5 Checker Challenge

    八皇后问题,最大输入13,单case,时限1s;

    和 HDOJ 不同的是:

    Do not precalculate the value and print it (or even find a formula for it); that's cheating. Work on your program until it can solve the problem properly. If you insist on cheating, your login to the USACO training pages will be removed and you will be disqualified from all USACO competitions. YOU HAVE BEEN WARNED.

    ( 不知道真的假的)

    /*
    PROG : checker
    LANG : C++
    */
    # include <stdio.h>
    # include <string.h>
    
    # define N 15
    
    int k, n = 0, m = 3;
    /********************************/
    int sol[N];
    char vis[3][3*N];
    
    void dfs(int cnt)
    {
        int i, j;
        if (cnt == k)
        {
            ++n;
            if (m)
            {
                --m;
                printf("%d", sol[1]);
                for (i = 2; i <= k; ++i) printf(" %d", sol[i]);
                putchar('\n');
            }
        }
        else for (i = 1; i <= k; ++i)
            if (!vis[0][i] && !vis[1][cnt+i] && !vis[2][cnt-i+k])
            {
                vis[0][i] = vis[1][cnt+i] = vis[2][cnt-i+k] = 1;
                sol[cnt+1] = i;
                dfs(cnt+1);
                vis[0][i] = vis[1][cnt+i] = vis[2][cnt-i+k] = 0;
            }
    }
    
    /********************************/
    void solve(void)
    {
        scanf("%d", &k);
        memset(vis, 0, sizeof(vis));
        dfs(0);
        printf("%d\n", n);
    }
    
    int main()
    {
        freopen("checker.in", "r", stdin);
        freopen("checker.out", "w", stdout);
        
        solve();
        
        fclose(stdin);
        fclose(stdout);
        
        return 0;
    }
  • 相关阅读:
    mxnet笔记
    8.1.18示例:使用forName()的扩展
    8.1.17使用1.2版本的用户自定义类装载器
    8.1.16 使用1.1版本的用户自定义类装载器
    8.1.13 _quick 指令
    8.1.12直接引用
    8.1.11编译时常量解析
    8.1.10装载约束
    8.1.8 解析CONSTANT_String_info入口
    8.1.7 解析CONSTANT_interfaceMethodref_info入口
  • 原文地址:https://www.cnblogs.com/JMDWQ/p/2648781.html
Copyright © 2011-2022 走看看