Cellular automata are mathematical idealizations of physical systems in which both space and time
are discrete, and the physical quantities take on a nite set of discrete values. A cellular automaton
consists of a lattice (or array), usually in nite, of discrete-valued variables. The state of such automaton
is completely speci ed by the values of the variables at each place in the lattice. Cellular automata
evolve in discrete time steps, with the value at each place (cell) being affected by the values of variables
at sites in its neighborhood on the previous time step. For each automaton there is a set of rules that
de ne its evolution.
For most cellular automata there are con gurations (states) that are unreachable: no state will
produce them by the application of the evolution rules. These states are called Gardens of Eden for
they can only appear as initial states. As an example consider a trivial set of rules that evolve every
cell into 0; for this automaton any state with non-zero cells is a Garden of Eden.
In general, nding the ancestor of a given state (or the non-existence of such ancestor) is a very hard,
compute intensive, problem. For the sake of simplicity we will restrict the problem to 1-dimensional
binary nite cellular automata. This is, the number of cells is a nite number, the cells are arranged in
a linear fashion and their state will be either `0' or `1'. To further simplify the problem each cell state
will depend only on its previous state and that of its immediate neighbors (the one to the left and the
one to the right).
The actual arrangement of the cells will be along a circumference, so that the last cell is next to
the rst.
Problem de nition
Given a circular binary cellular automaton you must nd out whether a given state is a Garden of
Eden or a reachable state. The cellular automaton will be described in terms of its evolution rules. For
example, the table below shows the evolution rules for the automaton: Cell = XOR(Lef t; Right).
Left Cell Right New
[i  1] [i] [i + 1] State
0 0 0 0 0 2
0
0 0 1 1 1 2
1
0 1 0 0 0 2
2
0 1 1 1 1 2
3
1 0 0 1 1 2
4
1 0 1 0 0 2
5
1 1 0 1 1 2
6
1 1 1 0 0 2
7
90 = Automaton Identi er
Notice that, with the restrictions imposed to this problem, there are only 256 different automata.
An identi er for each automaton can be generated by taking the New State vector and interpreting it
as a binary number (as shown in the table). For instance, the automaton in the table has identi er 90.
The Identity automaton (every state evolves to itself) has identi er 204.
Input
The input will consist of several test cases. Each input case will describe, in a single line, a cellular
automaton and a state. The rst item in the line will be the identi er of the cellular automaton you
must work with. The second item in the line will be a positive integer N (4 N 32) indicating the
number of cells for this test case. Finally, the third item in the line will be a state represented by a
string of exactly N zeros and ones. Your program must keep reading lines until the end of the input
(end of le).
Output
If an input case describes a Garden of Eden you must output the string GARDEN OF EDEN. If the input
does not describe a Garden of Eden (it is a reachable state) you must output the string REACHABLE.
The output for each test case must be in a different line.
Sample Input
0 4 1111
204 5 10101
255 6 000000
154 16 1000000000000000
Sample Output
GARDEN OF EDEN
REACHABLE
GARDEN OF EDEN
GARDEN OF EDEN

6765225
Accepted
  420 687
2016-08-05 22:12:39

题目大意:不要被什么“细胞自动机”吓到。意思是这样,在description中给定表格就是进化法则,给定一个细胞自动机的编号(从0~256)和目标数字,求进化时所用的中转数字。

思路:从表格可以得到启发,将细胞自动机的编号通过十转二算法转换为二进制数组,在自动机中寻找可能的运算路径,记录运算路径规定的左右细胞数字,进行搜索,若细胞数字的头尾的左右数字都可以连成串,则是合法的进化中转数字。

#include<cstdio>
#include<string>
#include<iostream>
using namespace std;
string str;
int s[35],att[8],ans[35],id,n;
bool dfs(int cur)
{
if(cur>=n)
return ((ans[0]==ans[n])&&(ans[1]==ans[n+1]));
for(int i=0;i<8;i++){
if((s[cur]==att[i])&&(!cur||(ans[cur]*4+ans[cur+1]*2==(i&6)))){
if(!cur){
ans[0]=((i&4)>0);
ans[1]=((i&2)>0);
}
ans[cur+2]=((i&1)>0);
if(dfs(cur+1))return 1;
}
}
return 0;
}
int main()
{
while(cin>>id>>n>>str){
for(int i=0;i<8;i++)
att[i]=(id>>i)&1;
for(int i=0;i<n;i++)
s[i]=str[i]-'0';
if(dfs(0))puts("REACHABLE");
else puts("GARDEN OF EDEN");
}
return 0;
}

uva10001 Garden of Eden的更多相关文章

  1. HDU5977 Garden of Eden(树的点分治)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5977 Description When God made the first man, he ...

  2. hdu-5977 Garden of Eden(树分治)

    题目链接: Garden of Eden Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

  3. HDU 5977 Garden of Eden(点分治求点对路径颜色数为K)

    Problem Description When God made the first man, he put him on a beautiful garden, the Garden of Ede ...

  4. Garden of Eden

    Garden of Eden Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others ...

  5. hdu5977 Garden of Eden

    都不好意思写题解了 跑了4000多ms 纪念下自己A的第二题 (我还有一道freetour II wa20多发没A...呜呜呜 #include<bits/stdc++.h> using ...

  6. HDU 5977 Garden of Eden

    题解: 路径统计比较容易想到点分治和dp dp的话是f[i][j]表示以i为根,取了i,颜色数状态为j的方案数 但是转移这里如果暴力转移就是$(2^k)^2$了 于是用FWT优化集合或 另外http: ...

  7. HDU5977 Garden of Eden 【FMT】【树形DP】

    题目大意:求有所有颜色的路径数. 题目分析:参考codeforces997C,先利用基的FMT的性质在$O(2^k)$做FMT,再利用只还原一位的特点在$O(2^k)$还原,不知道为什么网上都要点分治 ...

  8. HDU 5977 Garden of Eden (树形dp+快速沃尔什变换FWT)

    CGZ大佬提醒我,我要是再不更博客可就连一月一更的频率也没有了... emmm,正好做了一道有点意思的题,就拿出来充数吧=.= 题意 一棵树,有 $ n (n\leq50000) $ 个节点,每个点都 ...

  9. HDU 5977 Garden of Eden (树分治+状态压缩)

    题意:给一棵节点数为n,节点种类为k的无根树,问其中有多少种不同的简单路径,可以满足路径上经过所有k种类型的点? 析:对于路径,就是两类,第一种情况,就是跨过根结点,第二种是不跨过根结点,分别讨论就好 ...

随机推荐

  1. 腾讯bugly 的crash 上报和umeng的比较

    说到crash上传工具,大家肯定会第一时间想到umeng,不错,umeng 是最早推出 crash 上报的工具之一,在刚推出来的时候,特别受到ios开发人员的喜爱. 因为个时候,内存是手动管理的,很容 ...

  2. Asp.net中GridView使用详解(引)

    GridView无代码分页排序GridView选中,编辑,取消,删除GridView正反双向排序GridView和下拉菜单DropDownList结合GridView和CheckBox结合鼠标移到Gr ...

  3. Android上传图片到PHP服务器并且支持浏览器上传文件(word、图片、音乐等)

    暑假已经过了一半了,这才完成计划当中的第二个任务.虽然进度是慢了点.但也算是暑假的收获吧.下面我就把我学习当中的收获记录在此. 还是跟以往一样,先上图片. 操作的步骤:打开程序---->选择上传 ...

  4. 防止IOS6与IOS7图标不一致

    点击AppIcon在属性栏内找到iOS icon is pre-rendered打上勾. 如果之前已经安装过,需要先把APP卸载掉再安装.(因为模拟器有缓存) xcode4版本的话需要在INFO内增加 ...

  5. iOS 图片加载导致内存警告

    虽然UITableView和UICollectionView都有cell复用机制,但是如果利用SDWebImage加载的图片本身过大且cell复用池中的个数比较多(cell的Size越小,复用池中的c ...

  6. 【代码笔记】iOS-3个section,每个都有header.

    一,效果图: 二,工程目录. 三,代码 RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

  7. IOS NSTimer和CADisplayLink的用法

    IOS--NSTimer和CADisplayLink的用法 NSTimer初始化器接受调用方法逻辑之间的间隔作为它的其中一个参数,预设一秒执行30次.CADisplayLink默认每秒运行60次,通过 ...

  8. iOS 音乐

    iOS 音乐 这篇博客介绍的是较长的音频播放-音乐... 有关音效的介绍可以点击下面的连接进入... iOS 音效 首先导入框架:AVFoundation.framework 导入框架后我们在需要使用 ...

  9. chrome插件——Vimium 键盘手福利

    chrome插件——Vimium 键盘手福利 金刚 chrome chrome插件 Vimium 一直希望纯键盘操作,但是在浏览网页的时候,发现还是很难做到这点的.因为网页浏览的时候会有 各种各样的内 ...

  10. (视频) 《快速创建网站》1. 网站管理平台WordPress & 微软Azure 云计算简介

    网站并不神秘,过节了,在家闲的没事的,自己建个网站玩玩吧.每段视频不超过15分钟,地铁/公交/睡前/醒来看一段,几天之后变身建站专家,找老板加薪去! 在普通人眼里,创建网站是专业开发人员和IT工程师才 ...