[UVA][] 10001 - Garden of Eden@Morris' Blog|PChome Online 人新台
2013-04-20 10:28:34| 人2,032| 回0 | 上一篇 | 下一篇

[UVA][] 10001 - Garden of Eden

0 收藏 0 0 站台


  Garden of Eden 

Cellular automata are mathematical idealizations of physical systems in which both space and time are discrete, and the physical quantities take on a finite set of discrete values. A cellular automaton consists of a lattice (or array), usually infinite, of discrete-valued variables. The state of such automaton is completely specified 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 define its evolution.

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.

Problem definition 

Given a circular binary cellular automaton you must find 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(Left,Right).


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.

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 first item in the line will be the identifier of the cellular automaton you must work with. The second item in the line will be a positive integer N ( $4 le N le 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 file).

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 Sample Output 

GARDEN OF EDEN REACHABLE GARDEN OF EDEN GARDEN OF EDEN 



Miguel Revilla
2000-08-21

目真的很看懂,不把它想成生命就好。

一格如果是 1 左跟右分多少,根 function 之後,下一刻成什子(NewState)。
由於是的胞列,因此尾相接。因此下一刻得到新的胞。

而定的 ID 只不是 function 的代,原一下得到 function 即可。

目要的是,有有存在一 input 下一刻得到入的 target。
因此始,先法得到 target[0] = func(?),因此就知道 input[-1], input[0], input[1],
要得到 target[i] 必符合之前得到的 input[i-1], input[i], 然後得到 input[i+1] ...
最後再回查首尾是否可以得到 target[]

充一下 func(input[i-1], input[i], input[i+1]) = target[i]

#include <stdio.h>
int func[8];
int target[50], origin[50];
int ID, n, found;
char s[50];
void dfs(int idx) {
    if(found)   return;
    int i, j;
    if(idx == n-1) {
        i = (origin[n-2]<<2)|(origin[n-1]<<1)|(origin[0]<<0);
        j = (origin[n-1]<<2)|(origin[0]<<1)|(origin[1]<<0);
        if(target[idx] == func[i] && target[0] == func[j])
            found = 1;
        return;
    }
    for(i = 0; i < 8; i++) {
        if(func[i] == target[idx] && ((i>>2)&1) == origin[idx-1] && ((i>>1)&1) == origin[idx]) {
            origin[idx+1] = (i>>0)&1;
            dfs(idx+1);
            if(found)   return;
        }
    }
}
int main() {
    int i;
    while(scanf("%d %d %s", &ID, &n, s) == 3) {
        for(i = 0; i < n; i++)
            target[i] = s[i]-'0';
        for(i = 0; i < 8; i++)
            func[i] = (ID>>i)&1;
        found = 0;
        for(i = 0; i < 8; i++) {
            if(func[i] == target[0]) {
                origin[0] = (i>>1)&1;
                origin[1] = (i>>0)&1;
                dfs(1);
            }
        }
        if(found)
            puts("REACHABLE");
        else
            puts("GARDEN OF EDEN");
    }
    return 0;
}

台: Morris
人(2,032) | 回(0)| 推 (0)| 收藏 (0)|
全站分: 不分 | 人分: UVA |
此分下一篇:[UVA][三角形交集][段交、射法、凸包] 11122 - Tri Tri
此分上一篇:[UVA][dp] 10888 - Warehouse

是 (若未登入"人新台"看不到回覆唷!)
* 入:
入片中算式的果(可能0) 
(有*必填)
TOP
全文
ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86