Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* -- ITMO UNIVERSITY 2 ---*/
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <string>
- #include <cstring>
- #include <cmath>
- #include <algorithm>
- #include <vector>
- #include <set>
- #include <map>
- #include <ctime>
- #include <cassert>
- #define fs first
- #define sc second
- #define F first
- #define S second
- #define pb push_back
- #define mp make_pair
- #define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
- #define forit(it,v) for(typeof((v).begin()) it = v.begin() ; it != (v).end() ; ++it)
- #define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
- #define sz(a) ((int)(a).size())
- #define all(a) (a).begin(),a.end()
- #define pw(x) (1LL<<(x))
- static inline unsigned long long rdtsc() { unsigned long long d; __asm__ __volatile__ ("rdtsc" : "=A" (d) ); return d; }
- using namespace std;
- typedef long long ll;
- typedef double dbl;
- typedef vector<int> vi;
- typedef pair<int, int> pi;
- const int inf = (int)1e9;
- const dbl eps = 1e-9;
- /* --- main part --- */
- #define TASK "a"
- const int maxn = 20;
- int a[maxn][maxn];
- int b[maxn][maxn];
- int f[maxn][maxn];
- int dx[8] = {1, 1, 1, 0, -1, -1, -1, 0};
- int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
- int main()
- {
- #ifdef home
- assert(freopen(TASK".in", "r", stdin));
- assert(freopen(TASK".out", "w", stdout));
- #endif
- int test =0;
- while (1)
- {
- int n, m;
- scanf("%d%d", &n, &m);
- if (n == 0) break;
- forn(i, n) forn(j, m) a[i][j] = 0;
- int K;
- scanf("%d", &K);
- forn(i, K)
- {
- int x, y;
- scanf("%d%d", &x, &y);
- a[x - 1][y - 1] = 1;
- }
- int res = 0;
- forn(mask, 1 << (n * m))
- {
- int c = 0;
- forn(i, n) forn(j, m) b[i][j] = ((mask >> c++) & 1);
- forn(i, n) forn(j, m)
- {
- int alive = 0;
- forn(k, 8)
- {
- int i2 = i + dx[k];
- int j2 = j + dy[k];
- i2 = (i2 + n) % n;
- j2 = (j2 + m) % m;
- if (b[i2][j2]) alive += 1;
- }
- f[i][j] = 0;
- if (b[i][j] == 1 && 2 <= alive && alive <= 3) f[i][j] = 1;
- if (b[i][j] == 0 && alive == 3) f[i][j] = 1;
- }
- bool ok = true;
- forn(i, n) forn(j, m) if (f[i][j] != a[i][j]) ok = false;
- if (ok) res += 1;
- }
- printf("Case %d: ", ++test);
- if (res > 0) printf("%d possible ancestors.\n", res);
- else printf("Garden of Eden.\n");
- }
- #ifdef home
- eprintf("Time: %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement