Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. /* -- ITMO UNIVERSITY 2 ---*/
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstdlib>
  5. #include <string>
  6. #include <cstring>
  7. #include <cmath>
  8. #include <algorithm>
  9. #include <vector>
  10. #include <set>
  11. #include <map>
  12. #include <ctime>
  13. #include <cassert>
  14.  
  15. #define fs first
  16. #define sc second
  17. #define F first
  18. #define S second
  19. #define pb push_back
  20. #define mp make_pair
  21. #define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
  22. #define forit(it,v) for(typeof((v).begin()) it = v.begin() ; it != (v).end() ; ++it)
  23. #define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
  24. #define sz(a) ((int)(a).size())
  25. #define all(a) (a).begin(),a.end()
  26. #define pw(x) (1LL<<(x))
  27.  
  28. static inline unsigned long long rdtsc() { unsigned long long d; __asm__ __volatile__ ("rdtsc" : "=A" (d) ); return d; }
  29.  
  30. using namespace std;
  31.  
  32. typedef long long ll;
  33. typedef double dbl;
  34. typedef vector<int> vi;
  35. typedef pair<int, int> pi;
  36.  
  37. const int inf = (int)1e9;
  38. const dbl eps = 1e-9;
  39.  
  40. /* --- main part --- */
  41.  
  42. #define TASK "a"
  43.  
  44. const int maxn = 20;
  45.  
  46. int a[maxn][maxn];
  47. int b[maxn][maxn];
  48. int f[maxn][maxn];
  49.  
  50. int dx[8] = {1, 1, 1, 0, -1, -1, -1, 0};
  51. int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
  52.  
  53. int main()
  54. {
  55. #ifdef home
  56. assert(freopen(TASK".in", "r", stdin));
  57. assert(freopen(TASK".out", "w", stdout));
  58. #endif
  59. int test =0;
  60. while (1)
  61. {
  62. int n, m;
  63. scanf("%d%d", &n, &m);
  64. if (n == 0) break;
  65. forn(i, n) forn(j, m) a[i][j] = 0;
  66. int K;
  67. scanf("%d", &K);
  68. forn(i, K)
  69. {
  70. int x, y;
  71. scanf("%d%d", &x, &y);
  72. a[x - 1][y - 1] = 1;
  73. }
  74. int res = 0;
  75. forn(mask, 1 << (n * m))
  76. {
  77. int c = 0;
  78. forn(i, n) forn(j, m) b[i][j] = ((mask >> c++) & 1);
  79. forn(i, n) forn(j, m)
  80. {
  81. int alive = 0;
  82. forn(k, 8)
  83. {
  84. int i2 = i + dx[k];
  85. int j2 = j + dy[k];
  86. i2 = (i2 + n) % n;
  87. j2 = (j2 + m) % m;
  88. if (b[i2][j2]) alive += 1;
  89. }
  90. f[i][j] = 0;
  91. if (b[i][j] == 1 && 2 <= alive && alive <= 3) f[i][j] = 1;
  92. if (b[i][j] == 0 && alive == 3) f[i][j] = 1;
  93. }
  94. bool ok = true;
  95. forn(i, n) forn(j, m) if (f[i][j] != a[i][j]) ok = false;
  96. if (ok) res += 1;
  97. }
  98. printf("Case %d: ", ++test);
  99. if (res > 0) printf("%d possible ancestors.\n", res);
  100. else printf("Garden of Eden.\n");
  101. }
  102.  
  103. #ifdef home
  104. eprintf("Time: %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
  105. #endif
  106. return 0;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement