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. Android闹钟 AlarmManager的使用

    Android闹钟 AlarmManager的使用 AlarmManager介绍 AlarmManager这个类提供对系统闹钟服务的访问接口. 你可以为你的应用设定一个在未来某个时间唤醒的功能. 当闹 ...

  2. 深入浅出-iOS程序性能优化 (转载)

    iOS应用是非常注重用户体验的,不光是要求界面设计合理美观,也要求各种UI的反应灵敏,我相信大家对那种一拖就卡卡卡的 TableView 应用没什么好印象. iOS应用是非常注重用户体验的,不光是要求 ...

  3. C语言笔记

    .c是C语言源文件,在编写代码的时候创建 .o是目标文件,在编译成功的时候产生  .obj .out是可执行文件,在链接成功的时候产生 工具:clang编译器(Xcode3 gcc Xcode4 LL ...

  4. iOS解析数据时Error=3840

    1.解析JSon数据格式出错的问题 unescaped control character around character XXXX 和 The data couldn’t be read beca ...

  5. 【VLC-Android】LibVLC API简介(相当于VLC的MediaPlayer)

    前言 学新东西API很重要,这里抛砖引玉整理了一下,欢迎反馈! 声明 欢迎转载,但请保留文章原始出处:)  博客园:http://www.cnblogs.com 农民伯伯: http://over14 ...

  6. android 界面设计基本知识Ⅱ

    上一章讲述了Android界面设计时,一些基本控件的使用,本章主要讲述自定义控件,Fragment和Headler线程机制. 1.自定义控件 (1)基本知识 dp.sp和dx      px:像素点  ...

  7. 让我们喝喝下午茶,聊聊AJAX和JSON

    1.AJAX     [1] AJAX简介         > 全称:Asynchronous JavaScript And XML         > 直译:异步的JavaScript和 ...

  8. PreferenceScreen监听子项的刷新

    有个PreferenceScreen,他有一些个子项目.它的Summary需要根据子项的设置来改变的,所以需要监听子项的刷新事件. preferenceScreen.setOnPreferenceCh ...

  9. arcgis 随手记

    1,ArcGISDynamicMapServiceLayer   3.0  用  4.1 以后用MapImageLayer 代码如下: <!DOCTYPE html> <html&g ...

  10. groups, usermod, chown, chgrp, chmod

    Linux文件权限简介 Linux的每个文件可以由三种用户访问 属主权限:创建人的权限 属组权限:与创建同一个用户组的权限 其他权限:和创建人不在同一个用户组的用户的权限 当然,root用户拥有最高权 ...