Codeforces Gym 100650C The Game of Efil DFS
The Game of Efil
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88443#problem/C
Description
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 0, 1, 4, 5, 6, 7, or 8 occupied neighbors, the organism dies (0, 1: of loneliness; 4 thru 8: of overcrowding). • If an occupied cell has two or three occupied neighbors, the organism survives to the next generation. • 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 2 by 3 configuration: 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 m and n, indicating the number of rows and columns of the configuration, respectively. The next line will contain a nonnegative integer k indicating the number of “live” cells in the configuration. The following k lines each contain the row and column number of one live cell, where row and column numbering both start at zero. The final test case is followed by a line where m = n = 0 — this line should not be processed. You may assume that the product of m and n is no more than 16.
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.
HINT
题意
给你一个病毒产生或者消亡的规律,然后让你求这个状态下的图的上一状态一共有多少种
题解:
数据范围很小,n*m<=16,所以直接dfs出所有的状态就好了
然后再check
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200051
#define mod 10007
#define eps 1e-9
int Num;
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//**************************************************************************************
int M[][];
int d[][];
int cnt[][];
int d2[][];
int n,m;
int ans=;
int dx[]={,-,,-,,-,,};
int dy[]={,-,-,,,,,-};
int C(int x,int k)
{
if(x==-)
x=k-;
if(x==k)
return ;
return x;
}
int check()
{
memset(cnt,,sizeof(cnt));
memset(d2,,sizeof(d2));
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
for(int k=;k<;k++)
{
int xx=C(i+dx[k],n);
int yy=C(j+dy[k],m);
if(d[xx][yy]==)
cnt[i][j]++;
}
}
}
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(d[i][j]==)
{
if(cnt[i][j]==||cnt[i][j]==)
d2[i][j]=;
else
d2[i][j]=;
}
else
{
if(cnt[i][j]==)
d2[i][j]=;
}
}
}
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(d2[i][j]!=M[i][j])
return ;
}
}
return ;
}
int tot=;
void dfs(int x,int y)
{
if(x==n)
{
if(check())
ans++;
return;
}
d[x][y]=;
if(y==m-)
dfs(x+,);
else
dfs(x,y+);
d[x][y]=;
if(y==m-)
dfs(x+,);
else
dfs(x,y+);
d[x][y]=;
}
int main()
{
int t=;
while(cin>>n>>m)
{
if(n==&&m==)
break;
memset(M,,sizeof(M));
ans=;
int k=read();
for(int i=;i<k;i++)
{
int x=read(),y=read();
M[x][y]=;
}
dfs(,);
if(ans!=)
printf("Case %d: %d possible ancestors.\n",t++,ans);
else
printf("Case %d: Garden of Eden.\n",t++);
}
}
Codeforces Gym 100650C The Game of Efil DFS的更多相关文章
- Codeforces Gym 100650C The Game of Efil 模拟+阅读题
原题链接:http://codeforces.com/gym/100650/attachments/download/3269/20052006-acmicpc-east-central-north- ...
- Codeforces Gym 100338I TV Show 傻逼DFS,傻逼题
Problem I. TV ShowTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest ...
- Codeforces Gym 101252D&&floyd判圈算法学习笔记
一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...
- Codeforces Gym 101190M Mole Tunnels - 费用流
题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...
- Codeforces Gym 101623A - 动态规划
题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...
- 【Codeforces Gym 100725K】Key Insertion
Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...
- Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】
2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...
- codeforces gym 100553I
codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...
- CodeForces Gym 100213F Counterfeit Money
CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...
随机推荐
- 怎样查看Eclipse是32位还是64位
首先进入到Eclipse的安装目录,如下图: 查找到文件名为"eclipse.ini" 文件,使用文本编辑工具,或记事本打开,如下图: 如图中的红框所示,如果是win32.x8 ...
- HDU 4267-A Simple Problem with Integers(多个BIT)
题意: 2种操作 1 a b k c 在区间[a,b]中的(i-a)%k==0的位置i上的数+c 2 a 查询位置a的值 输出每次查询的值 分析: 开始想到多维的线段树,但比较麻烦,看了题解才知道,用 ...
- 使用DDMS测试安卓手机APP的性能(android)
安装/配置: 通过另外一个工具也可以测试手机客户端APP的性能,这就是android开发包中的DDMS工具(Dalvik Debug Monitor Service),先来说一下android开发包的 ...
- Python 变量 对象 引用
1.变量 变量第一次赋值时被创建,变量在使用前必须赋值 变量本身没有类型,变量类型为它引用的对象类型: 变量在使用时被替换成它引用的对象 2.对象 对象本身具有计数和类型,变量引用对象,当对象的引用变 ...
- 基于easyui的验证扩展
基于easyui的验证扩展 ##前言 自己做项目也有好几年的时间了,一直没有时间整理自己的代码,趁春节比较闲,把自己以前的代码整理了一篇.这是基于easyui1.2.6的一些验证扩展,2012年就开始 ...
- hadoop2.5发布:最新编译 32位、64位安装、源码包、API以及新特性
hadoop2.5发布:最新编译 32位.64位安装.源码包.API以及新特性 http://www.aboutyun.com/thread-8751-1-1.html (出处: about云开发) ...
- cmake编译win下64位obs
obs是一款开源编码推流工具,简单易用,非常流行.一次项目中,发现本台式机I3处理器下32位obs推流CPU使用率100%.而使用的第三方设备在64位下,性能较好.所以需要编译64位obs并且编译相应 ...
- Linux里实用命令之添加行号、文本和语法高亮显示
写在前面的话 本博主我,强烈建议,来看此博文的朋友们,都玩玩. 最好,在刚入门的时候呢,不加行号,不玩文本和语法高亮显示,以后会深有体会.磨炼自己! 步骤一:进入 /etc/virc配置文件 步骤二: ...
- 客户端接口AGENDA
日程 周二上午:完善客户端功能.接口定义. 周二下午:助教审查客户端代码.审查完成之后将发布接口定义. 提示 总之谢谢大家的支持.我们会尽量降低交互难度,让各位亲把精力专注于算法设计上面. 可以使用任 ...
- Spring EL regular expression example
Spring EL supports regular expression using a simple keyword "matches", which is really aw ...