Garden of Eden |
For most cellular automata there are configurations (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, finding 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 finite cellular automata. This is, the number of cells is a finite 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 first.
Left | Cell | Right | New | |||||
[i-1] | [i] | [i + 1] | State | |||||
0 | 0 | 0 | 0 | 0 * 20 | ||||
0 | 0 | 1 | 1 | 1 * 21 | ||||
0 | 1 | 0 | 0 | 0 * 22 | ||||
0 | 1 | 1 | 1 | 1 * 23 | ||||
1 | 0 | 0 | 1 | 1 * 24 | ||||
1 | 0 | 1 | 0 | 0 * 25 | ||||
1 | 1 | 0 | 1 | 1 * 26 | ||||
1 | 1 | 1 | 0 | 0 * 27 | ||||
90 | = | Automaton Identifier | ||||||
Notice that, with the restrictions imposed to this problem, there are only 256 different automata. An identifier 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 identifier 90. The Identity automaton (every state evolves to itself) has identifier 204.
The output for each test case must be in a different line.
0 4 1111 204 5 10101 255 6 000000 154 16 1000000000000000
GARDEN OF EDEN REACHABLE GARDEN OF EDEN GARDEN OF EDEN
题意:。。。其实好吧。这题最难的地方我觉得就是题意了。。根本看不懂啊有木有
我大概理解是,给定一个数字,要把它转换为8位2进制。。然后这个数字根据表中对应8种转换方式
然后输入一个n,在输入一个n位的2进制数,
根据前面那个转换方式,1只能在1的位置转换,0只能在0的位置转换,要求出如果能生成一个周期串,那么输出REACHABLE
否则输出GARDEN OF EDEN。。好吧 其实我也是参考了别人的代码才推测出得题意。。不知道有没有偏差。。
思路:知道题意后就是简单的深搜回溯了。。。写起来并不难。。
#include <stdio.h> #include <string.h> int k, n; char sb[35]; int s[35]; int ss[10]; int out[35]; int judge; int d[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}}; void dfs(int num) { if (judge == 1) return; if (num == n) { if (out[0] == out[num] && out[1] == out[num + 1]) { judge = 1; } return; } for (int i = 0; i < 8; i ++) { if (s[num] == ss[i] && (num == 0 || out[num] == d[i][0] && out[num + 1] == d[i][1])) { if (num == 0) { out[num] = d[i][0]; out[num + 1] = d[i][1]; } out[num + 2] = d[i][2]; dfs(num + 1); } } } int main() { while (scanf("%d%d%s", &k, &n, sb) != EOF) { judge = 0; memset(out, 0, sizeof(out)); for (int i = 0; i < n; i ++) { s[i] = sb[i] - '0'; } for (int i = 0; i < 8; i ++) { ss[i] = k % 2; k /= 2; } dfs(0); if (judge) printf("REACHABLE\n"); else printf("GARDEN OF EDEN\n"); } return 0; }