Advertisement
Guest User

Untitled

a guest
Nov 28th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. bool is_odd_graph[20000][20000];
  2. int main() {
  3.     is_odd_graph[1][1] = 1;
  4.     for(int i = 1; i < 20000; ++i) {
  5.         for (int j = 1; j <= i-1; ++j) {
  6.             if (!is_odd_graph[i-1][j]) continue;
  7.        
  8.             int previous_reduced = j;
  9.             int new_weight = 1;
  10.             while (true) {
  11.                 // Przypadek 1: w previous_reduced nie było new_weight lub zlepiamy je w jeden
  12.                 is_odd_graph[i][previous_reduced|new_weight] ^= 1;
  13.                 if (!(previous_reduced&new_weight)) break;
  14.                 // Przypadek 2: wyciągamy new_weight z previous_reduced i zlepiamy z naszym w podwójny
  15.                 previous_reduced -= new_weight;
  16.                 new_weight <<= 1;
  17.             }
  18.         }
  19.     }
  20.    
  21.     int Q;
  22.     scanf("%d", &Q);
  23.     REP(q,Q) {
  24.         int N, K;
  25.         scanf("%d%d", &N, &K);
  26.  
  27.         K = N-K;
  28.         bool res = is_odd_graph[N][K];
  29.         for (int lb = 1; !(lb&K); lb <<= 1) res ^= is_odd_graph[N][K + lb];
  30.         printf("%d\n", res);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement