zoukankan      html  css  js  c++  java
  • Hexagon Perplexagon 夜

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1945

    题目不难 dfs 就可以 不过后台数据相当的大 所以要尽量优化

    我是边搜边判 

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<map>
    #include<vector>
    #include<stack>
    #include<set>
    #include<map>
    #include<queue>
    #include<algorithm>
    #include<cmath>
    #define LL long long
    //#pragma comment(linker, "/STACK:1024000000,1024000000")
    using namespace std;
    const int INF=0x3f3f3f3f;
    //const int MOD=1000000009;
    const int N=35;
    int a[N][N],f[N][N];
    int k[N],l[N];
    bool had[N];
    bool hadans;
    void dfs(int x)
    {
        for(int i=0;i<7;++i)
        if(!had[i])
        {
            k[x]=i;
            if(x==0)
            {
                l[0]=f[k[0]][1];
            }else
            {
                int t=a[k[0]][l[0]+x-1];
                l[x]=f[k[x]][t];
                if(x>1&&a[k[x-1]][l[x-1]+5]!=a[k[x]][l[x]+1])
                continue;
                if(x==6&&a[k[x]][l[x]+5]==a[k[1]][l[1]+1])
                hadans=true;
            }
            had[i]=true;
            if(x<6)
            dfs(x+1);
            had[i]=false;
            if(hadans)
            return ;
        }
    }
    int main()
    {
        //freopen("data.in","r",stdin);
        int T;
        scanf("%d",&T);
        int ca=1;
        while(T--)
        {
            for(int i=0;i<7;++i)
            for(int j=0;j<6;++j)
            {
                scanf("%d",&a[i][j]);
                a[i][j+6]=a[i][j];
                f[i][a[i][j]]=j;
            }
            hadans=false;
            memset(had,false,sizeof(had));
            dfs(0);
            printf("Case %d:",ca++);
            if(hadans)
            {
                for(int i=0;i<7;++i)
                printf(" %d",k[i]);
    
            }else
            printf(" No solution");
            printf("\n");
        }
        return 0;
    }
    

      

  • 相关阅读:
    gdb --configuration
    firecracker 编译
    gvisor 编译
    gvisor
    rust Deref
    rust explicit
    rust move
    rust drop
    出租人对经营租赁的会计处理
    关于以公允价值计量的投资性房地产的处置
  • 原文地址:https://www.cnblogs.com/liulangye/p/2886830.html
Copyright © 2011-2022 走看看