Sicily 1171. The Game of Efil
2014-12-22 18:16
453 查看
// DFS #include <iostream> #include <cstdio> #include <cstring> using namespace std; int m, n; int res; int dx[8] = { -1, -1, 0, 1, 1, 1, 0, -1 }; int dy[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }; int d[16][16], tar[16][16]; void cal() { int around, _new; for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) { around = 0; for (int k = 0; k < 8; k++) // 省去对越界的判断 if (d[(i + dx[k] + m) % m][(j + dy[k] + n) % n]) around++; if (around == 3) _new = 1; else if (d[i][j] == 1 && around == 2) _new = 1; else _new = 0; // 生成一个格子判断一下 if (tar[i][j] != _new) return; } res++; return; } void dfs(int x, int y) { if (x == m) { cal(); return; } // 利用DFS遍历状态 d[x][y] = 0; if (y == n - 1) dfs(x + 1, 0); else dfs(x, y + 1); d[x][y] = 1; if (y == n - 1) dfs(x + 1, 0); else dfs(x, y + 1); } int main(int argc, char **argv) { int C = 1; while (cin >> m >> n && (m | n)) { memset(tar, 0, sizeof(tar)); int k; scanf("%d", &k); int x, y; for (int i = 0; i < k; ++i) { scanf("%d%d", &x, &y); tar[x][y] = 1; } res = 0; dfs(0, 0); if (res) printf("Case %d: %d possible ancestors.\n", C++, res); else printf("Case %d: Garden of Eden.\n", C++); } return 0; }
相关文章推荐
- soj1171 The Game of Efil
- sicily 1202. The Bank of Kalii
- 2014百度之星复赛解题报告:The Game of Coins
- 4:55 part of the game
- 【DirectX11-Tutorial】win32基础1-游戏运行的各个阶段The Parts of a game
- Codeforces Round #428 (Div. 2) B. Game of the Rows(贪心)
- The Game of 31 (博弈)
- Gym 101147.A - The game of Osho(SG函数+二项展开)
- HDU 4839 The Game of Coins _(:зゝ∠)_
- CF 451 C Predict Outcome of the Game(数学题)
- Sicily 1202. The Bank of Kalii
- The game of life(生命游戏)新算法
- 2014百度之星复赛解题报告:The Game of Coins
- Mastering the game of Go without human knowledge笔记
- Codeforce 839 -- B Game of the Rows 【思维 + 贪心】
- Game of the Rows CodeForces - 839B 详细题解
- hdu 4155 The Game of 31 博弈论
- Codeforces Round #428 (Div. 2)-贪心&模拟-B. Game of the Rows
- 451 C. Predict Outcome of the Game
- AlphaGo Zero论文中文版:Mastering the game of Go without human knowledge