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. Tomcat https自制证书和浏览器配置

    Tomcat配置成https后,如过使用的是自己的证书,登陆首页时,总是提示证书安全问题,网上的很多资料有描述,但比较复杂,找了几个配置不成功,现在描述一个比较简单的方法. 生成证书的脚本 #!/bi ...

  2. JavaScriptSerializer序列化时间处理

    JavaScriptSerializer序列化时间后会把时间序列化成N进制的鬼数据,于是查了下质料坐下记录 假设list = News List<Text>(){new Text(){id ...

  3. ios7 tableview被navigationbar挡住

    用ego下拉刷新的时候,每次在ios7时,tableview都会上移...导致被navagationbar挡住.ios6是正常的,于是在init的时候添加如下代码... NSComparisonRes ...

  4. sqlite API模型

     每一个数据库连接可以包括多个数据库文件,一个主数据库文件和attached的几个数据库文件. 每一个数据库文件都有自己的B-tree和pager. 数据库连接(connection)和事务(tra ...

  5. Android图表类库:WilliamChart

    WilliamChart是基于Views的Android图表类库,帮助开发者在Android应用中实现折线图.柱状图和堆叠柱状图.数值发生变化时图表也会以动画的效果发生变化. At the momen ...

  6. 如何处理Android Studio 上面关于 update 和 commit 小箭头的消失

    问题: android studio 在关联 SVN 或者 git 服务后,会在工具栏出现 update 和 commit 小箭头 如图: 但是,有时你打开工程的时候,发现这两个小箭头却消失不见了 如 ...

  7. 基于SolrCloud的内容搜索和热点推送

    ➠更多技术干货请戳:听云博客 什么是热点 我认为热点有时效性和受众面 用户关注从低到高再到低的内容 .有公共热点和分类热点.例如医辽养老全民关注,科技汽车等只有特定的人群关注. 推送的条件 搜索频次达 ...

  8. 【代码笔记】iOS-仿QQ空间,歌曲播放

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> #import <AVFoundation/AVFo ...

  9. SQL速记

    集合操作       WITH a AS ( SELECT 1 id UNION SELECT 2 ), b AS ( SELECT 1 id UNION SELECT 3 ) SELECT * FR ...

  10. 利用iframe实现无刷新上传处理

    继上一篇对上传异常进行处理之后,当上传异常的时候的错误体验并不是很好,这里介绍用iframe来进行错误提示 拦截错误 @ExceptionHandler(MaxUploadSizeExceededEx ...