Uva10001 Garden of Eden

简介: Uva10001 Garden of Eden
#include <stdio.h>inta[40], f[10], A[40], n;
intd[10][3] = {{0, 0, 0},
    {0, 0, 1},
    {0, 1, 0},
    {0, 1, 1},
    {1, 0, 0},
    {1, 0, 1},
    {1, 1,0},
    {1, 1, 1}};
charb[40];
intdfs(cur)
{
inti;
if (cur==n-1||cur==n) {
for (i=0; i<8; i++) {
if (f[i] ==a[cur] &&d[i][0] ==A[cur-1] &&d[i][1] ==A[cur] &&d[i][2] ==A[cur+1]) {
if (cur==n-1&&!dfs(cur+1))
return0;
elsereturn1;
            }
        }
    } else {
for (i=0; i<8; i++) {
if (f[i] ==a[cur] &&d[i][0] ==A[cur-1] &&d[i][1] ==A[cur]) {
A[cur+1] =d[i][2];
if (dfs(cur+1))
return1;
            }
        }
    }
return0;
}
intmain()
{
inti, k, id, ok;
#ifndef ONLINE_JUDGEfreopen("d:\\uva_in.txt", "r", stdin);
#endifwhile (scanf("%d%d%s", &id, &n, b+1) ==3) {
for (i=1; i<=n; i++)
a[i] =b[i] -'0';
k=id;
for (i=0; i<8; i++) {
f[i] =k%2;
k/=2;
        }
ok=1;
for (i=0; i<8; i++) {
if (a[1] ==f[i]) {
A[0] =d[i][0];
A[1] =d[i][1];
A[2] =d[i][2];
A[n] =A[0];
A[n+1] =A[1];
if (dfs(2)) {
ok=0;
break;
                }
            }
        }
if (ok)
printf("GARDEN OF EDEN\n");
elseprintf("REACHABLE\n");
    }
return0;
}
目录
相关文章
uva10038 Jolly Jumpers
uva10038 Jolly Jumpers
36 0
uva10112 Myacm Triangles
uva10112 Myacm Triangles
42 0
UVa 10082 WERTYU
Problem Description A common typing error is to place the hands on the keyboard one row to the right of the correct position.
888 0
|
机器学习/深度学习
|
C++
UVA 之10010 - Where's Waldorf?
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/SunnyYoona/article/details/24863879 ...
710 0
|
存储 固态存储
uva 10054 - The Necklace
点击打开链接uva 10054 思路: 欧拉回路 分析: 1 对于一个无向图来说如果这个图是一个欧拉图,那么必须满足该图是连通的并且每个点的度数都是偶数 2 题目给定n条边的无向图问我们是否是一个欧拉图,是的话输出欧拉图的一条路径 3 ...
838 0
uva 11627 Slalom
点击打开链接uva 11627 思路:二分答案 分析: 1 给定S个滑雪板的速度,问是否可以找到一个滑板使得通过所有的门的时间最少,如果找不到输出IMPOSSIBLE 2 很明显的二分题目,我们知道了二分那应该怎么判断是否可以通过所有...
1064 0