UVA 10001 Garden of Eden

本文详细解析了UVA-10001题目的解题思路及实现过程,通过递归深度优先搜索算法寻找可能的原始状态串,最终判断目标状态是否可达。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

UVA-10001

题意:
题目我也看了好久才看懂,参看http://www.cnblogs.com/staginner/archive/2011/09/07/2169351.html的解释,想了好久。
大概意思是题目给的那个表格的前3列是固定的,但是它们得到的new state是根据Automaton Identfier的01串在第i位的值来决定的。
如题目中Automaton Identfier = 90。那么一个串 00010101,进行循环变换,在后面补上开头的2个。
0001010100。 000 = 0 ,001 = 1 ,010 = 0,101 = 0,010 = 0,101 = 0,010 = 0,100 = 1。
转成后新串为 0100001。
给出Automaton Identfier码和新串的位数和新串。求是否存在一个原串可以通过题目所述规则变成新串。
解题思路:
tmep[i]为原串的第i位。
先把Automaton Identfier转成01串,然后枚举,新串的第一个要1的话,就要取Automaton Identfier中为1的位置的3位来作原串的前三位,然后知道2位了,看第二位要0还是1,找到Automaton Identfier中满足的那个,并比较temp[1] temp[2]是否满足给定的对应的三位01串中对应的前2位,满足就temp[3]就取三位01串的第三个。去枚举第四个。以此类推。

/*************************************************************************
    > File Name: UVA-10001.cpp
    > Author: Narsh
    > 
    > Created Time: 2016年07月27日 星期三 19时56分14秒
 ************************************************************************/

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int rule[8][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}};
int ati[15],tar[1100],temp[1000],n,m,aut;
bool flag;
void dfs(int x) {
    if (x > n) {
        if (temp[0] == temp[n] && temp[1] == temp[n+1]) flag=true;
        return ;
    }
    for (int i = 0; i < 8; i++) 
        if (tar[x] == ati[i] && rule[i][0] == temp[x-1] && rule[i][1] == temp[x]) {
            temp[x+1] = rule[i][2];
            dfs(x+1);
        }
}
int main() {
    while (scanf("%d%d",&aut,&n) != EOF) {
        for (int i = 1; i <= n; i++) 
            scanf("%1d",&tar[i]);
        for (int i = 0; i < 8; i++)
            if (aut & (1<<i)) ati[i] = 1;
            else ati[i]=0;
        flag = false;
        for (int i = 0; i < 8; i++) 
            if (ati[i] == tar[1]) {
                temp[0]=rule[i][0];
                temp[1]=rule[i][1];
                temp[2]=rule[i][2];
                dfs(2);
                if (flag) break;
            }
        if (flag) printf("REACHABLE\n");
        else printf("GARDEN OF EDEN\n");
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值