Codeforces Gym100650C The Game of Efil
来源:互联网 发布:淘宝开网店哪里进货 编辑:程序博客网 时间:2024/05/16 08:37
Problem C: The Game of Efil
Almost anyone who has ever taken a class in computer science is familiar with the “Game of Life,” John Conway’s cellular automata with extremely simple rules of birth, survival, and death that can give rise to astonishing complexity.
The game is played on a rectangular field of cells, each of which has eight neighbors (adjacent cells). A cell is either occupied or not. The rules for deriving a generation from the previous one are:
• If an occupied cell has
• If an occupied cell has two or three occupied neighbors, the organism survives to the next gener- ation.
• If an unoccupied cell has three occupied neighbors, it becomes occupied (a birth occurs).
One of the major problems researchers have looked at over the years is the existence of so-called “Garden of Eden” configurations in the Game of Life — configurations that could not have arisen as the result of the application of the rules to some previous configuration. We’re going to extend this question, which we’ll call the “Game of Efil”: Given a starting configuration, how many possible parent configurations could it have? To make matters easier, we assume a finite grid in which edge and corner cells “wrap around” (i.e., a toroidal surface). For instance, the
has exactly three possible parent configurations; they are:
You should note that when counting neighbors of a cell, another cell may be counted as a neighbor more than once, if it touches the given cell on more than one side due to the wrap around. This is the case for the configurations above.
Input
There will be multiple test cases. Each case will start with a line containing a pair of positive integers
Output
For each test case you should print one line of output containing the case number and the number of possible ancestors. Imitate the sample output below. Note that if there are 0 ancestors, you should print out
Garden of Eden.
Sample Input
2 3
2
0 0
0 1
3 3
4
0 0
0 1
0 2
1 1
3 3
5
0 0
1 0
1 2
2 1
2 2
0 0
Sample Output
Case 1: 3 possible ancestors.
Case 2: 1 possible ancestors.
Case 3: Garden of Eden.
题意
一个网格,对于被占用的格子,如果它周围八个格子中被占用的格子有2个或3个,下一代继续被占用,否则清空。对于空格子,如果周围有三个被占用,下一代就被占用,否则清空。边界是连通的,也就是
题解
代码
#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <queue>#include <vector>#include <map>#define fout freopen("out.txt","w",stdout)#define fin freopen("in.txt","r",stdin)using namespace std;int dx[]={1,1,1,-1,-1,-1,0,0};int dy[]={-1,0,1,-1,0,1,-1,1};int n,m,num,status,r,c,ans,MAX,cas=1;int cal(int x,int y){ if(x<0) x=n-1; else if(x>=n) x=0; if(y<0) y=m-1; else if(y>=m) y=0; return x*m+y;}int cal_next(int s){ int next=s; int pn,cr; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { pn=0; cr=1<<cal(i,j); for(int k=0;k<8&&pn<4;k++) { if(s&(1<<cal(i+dx[k],j+dy[k]))) pn++; } if(s&cr) { if(pn<2||pn>3) next^=cr; } else if(pn==3) next|=cr; } } return next;}int main(){ while(scanf("%d%d",&n,&m)==2&&m&&n) { MAX=1<<(n*m); status=0; ans=0; scanf("%d",&num); while(num--) { scanf("%d%d",&r,&c); status|=(1<<cal(r,c)); } for(int i=0;i<MAX;i++) { if(cal_next(i)==status) ans++; } if(ans) printf("Case %d: %d possible ancestors.\n",cas++,ans); else printf("Case %d: Garden of Eden.\n",cas++); } return 0;}
- Codeforces Gym100650C The Game of Efil
- Codeforces Gym 100650C The Game of Efil DFS
- soj1171 The Game of Efil
- Sicily 1171. The Game of Efil
- sicily 1171. The Game of Efil
- Sicily 1171. The Game of Efil 【利用完全二叉树遍历构造序列】
- Game of the Rows CodeForces
- Game of the Rows CodeForces
- codeforces--C. Predict Outcome of the Game
- codeforces 839 B Game of the Rows
- Codeforces 839B-Game of the Rows
- Codeforces #258 (Div. 2) C. Predict Outcome of the Game
- Codeforces 451C Predict Outcome of the Game
- Codeforces 451C Predict Outcome of the Game(暴力)
- codeforces 258(Div.2) C. Predict Outcome of the Game
- Codeforces Div. 2 #258-C. Predict Outcome of the Game
- CodeForces 451 C. Predict Outcome of the Game
- Codeforces 451C. Predict Outcome of the Game
- POJ-1258 Agri-Net(最小生成树[Prim])
- Resizing array笨办法,每次都要新建一个临时数组
- c实现极简单的正则表达式解析
- EXISTS的简单程序
- Android中的消息机制-源码分析
- Codeforces Gym100650C The Game of Efil
- 小P寻宝记——粗心的基友
- 专访罗升阳:老罗的Android之旅
- Interleaving String
- HTML5+ 打开关闭侧滑窗口
- C++手稿:STL入门
- scanf和循环
- 浅谈ANR及如何分析解决ANR.1
- jboss eap 6.3 域(Domain)模式配置