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;
}
目录
相关文章
|
12月前
uva 10340 all in all
输入两个字符串s和t,判断是否可以从t中删除0个或多个字符(其他字符顺序不变),得到字符串是。
34 0
uva375 Inscribed Circles and Isosceles Triangles
uva375 Inscribed Circles and Isosceles Triangles
38 0
UVa11776 - Oh Your Royal Greediness!
UVa11776 - Oh Your Royal Greediness!
49 0
UVa 10082 WERTYU
UVa 10082 WERTYU
123 0
|
C++
UVA 之10010 - Where's Waldorf?
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/SunnyYoona/article/details/24863879 ...
707 0
|
机器学习/深度学习 人工智能
uva 10870 Recurrences
点击打开uva 10870 思路:构造矩阵+矩阵快速幂 分析: 1 题目给定f(n)的表达式 f(n) = a1 f(n - 1) + a2 f(n - 2) + a3 f(n -3) + .
731 0
uva 1394 - And Then There Was One
点击打开链接uva 1394 思路: 数学递推 分析: 1 题目是一道变形的约瑟夫环变形问题 2 网上看到一篇很好的数学递推法 问题描述:n个人(编号0~(n-1)),从0开始报数,报到(m-1)的退出,剩下的人继续从0开始报数。
980 0
|
JavaScript 定位技术
uva 10047 - The Monocycle
点击打开链接uva 10047 思路:bfs 分析: 1 题目给定一个起始的状态然后要求是否可以到达目标状态 2 这些状态包括了位置,方向,底面颜色。
846 0