Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
844
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1.  
  2. /**
  3.  * Author: Sergey Kopeliovich (Burunduk30@gmail.com)
  4.  * Случайное блуждание от случайной точки на глубину 10n
  5.  * Score: 96
  6.  */
  7.  
  8. #include <cstdio>
  9. #include <cstdlib>
  10. #include <cassert>
  11.  
  12. #define forn(i, n) for (int i = 0; i < (int)(n); i++)
  13.  
  14. const int N = 200;
  15. const int M = N * N;
  16.  
  17. int n, m, x[N], ind[M][3], e[M][3];
  18.  
  19. int main() {
  20.   assert(scanf("%d%d", &n, &m) == 2 && n <= N && m <= M);
  21.   forn(i, m)
  22.     forn(j, 3)
  23.       scanf("%d%d", &ind[i][j], &e[i][j]), ind[i][j]--;
  24.  
  25.   for (int cnt = 0;; cnt++) {
  26.     forn(i, n)
  27.       x[i] = rand() % 2;
  28.     forn(_, 10 * n) {
  29.       int bad = 0;
  30.       forn(j, m) {
  31.         int good = (x[ind[j][0]] == e[j][0] || x[ind[j][1]] == e[j][1] || x[ind[j][2]] == e[j][2]);
  32.         if (!good) {
  33.           int t = rand() % 3;
  34.           bad = 1, x[ind[j][t]] = e[j][t];
  35.         }
  36.       }
  37.       if (!bad) {
  38.         forn(i, n)
  39.           putchar('0' + x[i]);
  40.         fprintf(stderr, "cnt = %d\n", cnt);
  41.         return 0;
  42.       }
  43.     }
  44.   }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement