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 | 420 | 687 |
题目大意:不要被什么“细胞自动机”吓到。意思是这样,在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; }