Codeforces Gym 100650C The Game of Efil 模拟+阅读题
原题链接:http://codeforces.com/gym/100650/attachments/download/3269/20052006-acmicpc-east-central-north-america-regional-contest-ecna-2005-en.pdf
题意
玩过这个游戏的人会比较熟悉,题目指出,每个细胞如果四周细胞太少了,就会孤独而死,如果细胞周围细胞太多了,就会挤死。给你个布局,问你他的上一代布局会有几种。不过这道题的关键在于wrap around这个词,即边界是循环的。
题解
做法是直接暴力枚举上一个的状态,然后检查。
代码
#include<queue>
#include<vector>
#include<iostream>
#include<cstring>
#include<cstdio>
#define MAX_N 16
using namespace std; int n,m; bool G[MAX_N][MAX_N];
int k; int dx[]={,,-,,,,-,-},dy[]={,,,-,-,,,-}; bool v[MAX_N][MAX_N]; void generate() {
bool tmp[MAX_N][MAX_N];
memset(tmp,,sizeof(tmp));
for (int i = ; i < n; i++)
for (int j = ; j < m; j++) {
int cnt = ;
for (int k = ; k < ; k++) {
int nx = dx[k] + i, ny = dy[k] + j;
nx = (nx + n) % n, ny = (ny + m) % m;
if (v[nx][ny])cnt++;
}
if (v[i][j]) {
if (cnt <= || cnt >= )
tmp[i][j] = ;
else
tmp[i][j] = ;
}
else if (cnt == )tmp[i][j] = ;
}
for (int i = ; i < n; i++)
for (int j = ; j< m; j++)v[i][j] = tmp[i][j];
} bool check(){
for(int i=;i<n;i++)
for(int j=;j<m;j++)if(G[i][j]!=v[i][j])return false;
return true;
} int main() {
int cas = ;
while (true) {
int ans = ;
scanf("%d%d", &n, &m);
if (n == && m == )break;
memset(G, , sizeof(G));
scanf("%d", &k);
for (int i = ; i < k; i++) {
int u, v;
scanf("%d%d", &u, &v);
G[u][v] = ;
}
for (int s = ; s < ( << (n * m)); s++) {
int t = s;
memset(v, , sizeof(v));
for (int i = ; i < n; i++)
for (int j = ; j < m; j++) {
if (t & )v[i][j] = ;
else v[i][j]=;
t >>= ;
}
generate();
if (check())ans++;
}
if (ans)
printf("Case %d: %d possible ancestors.\n", ++cas, ans);
else
printf("Case %d: Garden of Eden.\n", ++cas);
}
return ;
}
Codeforces Gym 100650C The Game of Efil 模拟+阅读题的更多相关文章
- Codeforces Gym 100650C The Game of Efil DFS
The Game of EfilTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/v ...
- Codeforces Gym 102392F Game on a Tree (SEERC2019 F题) 题解
题目链接:https://codeforces.com/gym/102392/problem/F 题意:被这题题意坑了很久,大意是说有一棵根为 \(1\) 的树,每个节点初始都是白色, \(Alice ...
- Codeforces Gym 100269K Kids in a Friendly Class 构造题
Kids in a Friendly Class 题目连接: http://codeforces.com/gym/100269/attachments Description Kevin resemb ...
- Codeforces Gym 101194G Pandaria (2016 ACM-ICPC EC-Final G题, 并查集 + 线段树合并)
题目链接 2016 ACM-ICPC EC-Final Problem G 题意 给定一个无向图.每个点有一种颜色. 现在给定$q$个询问,每次询问$x$和$w$,求所有能通过边权值不超过$w$的 ...
- 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 ...
随机推荐
- 多线程辅助类之CyclicBarrier(四)
CyclicBarrier是一个线程辅助类,和<多线程辅助类之CountDownLatch(三)>功能类似,都可以实现一组线程的相互等待.要说不通点,那就是CyclicBarrier在释放 ...
- Huawei warns against 'Berlin Wall' in digital world
From China Daily Huawei technologies criticized recent registration imposed on the Chinese tech comp ...
- Linux学习-systemctl 针对 service 类型的配置文件
systemctl 配置文件相关目录简介 现在我们知道服务的管理是透过 systemd,而 systemd 的配置文件大部分放置于 /usr/lib/systemd/system/ 目录内. 该目录的 ...
- SPOJ QTREE6 Query on a tree VI 树链剖分
题意: 给出一棵含有\(n(1 \leq n \leq 10^5)\)个节点的树,每个顶点只有两种颜色:黑色和白色. 一开始所有的点都是黑色,下面有两种共\(m(1 \leq n \leq 10^5) ...
- LSTM 应用于股票市场
https://zhuanlan.zhihu.com/p/27112144 1.LSTM对于非平稳数据的预测效果没有平稳数据好 2.神经网络的过拟合:在训练神经网络过程中,“过拟合”是一项尽量要避免的 ...
- [转载]ExtJs4 笔记(2) ExtJs对js基本语法扩展支持
作者:李盼(Lipan)出处:[Lipan] (http://www.cnblogs.com/lipan/) 本篇主要介绍一下ExtJs对JS基本语法的扩展支持,包括动态加载.类的封装等. 一.动态引 ...
- selenium - js日历控件处理
# 13. js处理日历控件 ''' 在web自动化的工程中,日历控制大约分为两种: 1. 可以直接输入日期 2. 通过日历控件选择日期 基本思路: 利用js去掉readonly属性,然后直接输入时间 ...
- python安装和eclipse安装及环境变量配置
非常好的技术文档,链接如下: http://jingyan.baidu.com/article/eb9f7b6da950c4869364e8f5.html 感谢作者的分享 http://python. ...
- 51nod 1010 只包含因子2 3 5的数 二分答案
1010 只包含因子2 3 5的数 K的因子中只包含2 3 5.满足条件的前10个数是:2,3,4,5,6,8,9,10,12,15. 所有这样的K组成了一个序列S,现在给出一个数n,求S中 > ...
- Centos7系统rc.local不起作用问题
Centos7系统rc.local不起作用问题 来源 https://www.cnblogs.com/xjz00/p/7729405.html Centos7已经写了要chmod +x /etc/rc ...