uva10001 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 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的更多相关文章
- HDU5977 Garden of Eden(树的点分治)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5977 Description When God made the first man, he ...
- hdu-5977 Garden of Eden(树分治)
题目链接: Garden of Eden Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
- 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 ...
- Garden of Eden
Garden of Eden Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- hdu5977 Garden of Eden
都不好意思写题解了 跑了4000多ms 纪念下自己A的第二题 (我还有一道freetour II wa20多发没A...呜呜呜 #include<bits/stdc++.h> using ...
- HDU 5977 Garden of Eden
题解: 路径统计比较容易想到点分治和dp dp的话是f[i][j]表示以i为根,取了i,颜色数状态为j的方案数 但是转移这里如果暴力转移就是$(2^k)^2$了 于是用FWT优化集合或 另外http: ...
- HDU5977 Garden of Eden 【FMT】【树形DP】
题目大意:求有所有颜色的路径数. 题目分析:参考codeforces997C,先利用基的FMT的性质在$O(2^k)$做FMT,再利用只还原一位的特点在$O(2^k)$还原,不知道为什么网上都要点分治 ...
- HDU 5977 Garden of Eden (树形dp+快速沃尔什变换FWT)
CGZ大佬提醒我,我要是再不更博客可就连一月一更的频率也没有了... emmm,正好做了一道有点意思的题,就拿出来充数吧=.= 题意 一棵树,有 $ n (n\leq50000) $ 个节点,每个点都 ...
- HDU 5977 Garden of Eden (树分治+状态压缩)
题意:给一棵节点数为n,节点种类为k的无根树,问其中有多少种不同的简单路径,可以满足路径上经过所有k种类型的点? 析:对于路径,就是两类,第一种情况,就是跨过根结点,第二种是不跨过根结点,分别讨论就好 ...
随机推荐
- 之二:CAKeyframeAnimation - 关键帧动画
是CApropertyAnimation的子类,跟CABasicAnimation的区别是:CABasicAnimation只能从一个数值(fromValue)变到另一个数值(toValue),而CA ...
- mysql innodb 奔溃问题
ps -A | grep -i mysql kill 列出来的进程 service mysql start 我的问题就解决了 ------------------------------------- ...
- 复杂sql分组查询 ( pivot)
一个数据表里面字段有年.月.日.金额.支付方式等字段,然后现在想写个sql语句,把每一天的每种支付方式金额(支付方式有多重)排在同一行, 最后在增加一列小计当前的所有支付方式的金额.如下图: 原sql ...
- iOS开发之多媒体API (转载)
视频格式可以分为适合本地播放的本地影像视频和适合在网络中播放的网络流媒体影像视频两大类.尽管后者在播放的稳定性和播放画面质量上可能没有前者 优秀,但网络流媒体影像视频的广泛传播性使之正被广泛应用于视频 ...
- 改变Android ProgressBar样式颜色
地址: http://blog.csdn.net/lvxiangan/article/details/9110121
- iOS 学习 - 15.添加水印
绘制到位图 下面利用位图图形上下文给一个图片添加水印,在下面的程序中我们首先创建上下文,然后在上下文中绘制图片.直线和文本,最后从当前位图上下文中取得最终形成的新图片显示到界面 - (void)vie ...
- apache 虚拟ip
参考 http://blog.sina.com.cn/s/blog_5d8ca1e90100hnpv.html <VirtualHost 127.0.0.1:80> Docume ...
- Mac OS 文件、文件夹重命名的方法
在Mac OS中,文件和文件名重命名的方法非常简单 选中你想要命名的文件或者文件夹,按回车,可以直接重命名,输入你要修改的内容,确认后,再按回车就OK啦--- 希望能对你有所帮助^_^
- 手机屏幕滑动效果框架——flipsnap
下午有时间,研究了下手机网页开发方面的内容.其中关于手机手势滑屏操作.发现有比较好的jquery 插件--flipsnap. 官方网站:http://pxgrid.github.com/js-flip ...
- ruby + watir 自动化上传图片文件解决方案
watir自动化捕获上传图片元素: require 'watir' include Watir require 'test/unit' class TC_recorded < Test::Uni ...