#include <bits/stdc++.h> using namespace std; const int N = (1 << 14) + 5; int odp[1000][1000] = { {0}, // 0 {1, 0, 0}, //1 {1, 1, 0, }, //2 {1, 0, 1, 0, 0}, //3 {1, 0, 0, 1, 0, 0}, //4 {1, 1, 0, 1, 1, 0, 0}, //5 {1, 1, 0, 1, 0, 1, 0, 0}, //6 {1, 0, 1, 1, 0, 0, 1, 0, 0}, //7 {1, 0, 0, 0, 1, 0, 1, 1, 0, 0} // 8 }; int solve(int n,int k) { if (n <= 8) return odp[n][k]; if (k == 0 || k == n - 1) return 1; if (k == 1) { if (((n+1)/2) % 2 == 1) return 1; return 0; } return rand() % 2; } int main() { int q, n, k; scanf("%d", &q); while(q--) { scanf("%d%d", &n, &k); printf("%d\n",solve(n, k)); } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #include <bits/stdc++.h> using namespace std; const int N = (1 << 14) + 5; int odp[1000][1000] = { {0}, // 0 {1, 0, 0}, //1 {1, 1, 0, }, //2 {1, 0, 1, 0, 0}, //3 {1, 0, 0, 1, 0, 0}, //4 {1, 1, 0, 1, 1, 0, 0}, //5 {1, 1, 0, 1, 0, 1, 0, 0}, //6 {1, 0, 1, 1, 0, 0, 1, 0, 0}, //7 {1, 0, 0, 0, 1, 0, 1, 1, 0, 0} // 8 }; int solve(int n,int k) { if (n <= 8) return odp[n][k]; if (k == 0 || k == n - 1) return 1; if (k == 1) { if (((n+1)/2) % 2 == 1) return 1; return 0; } return rand() % 2; } int main() { int q, n, k; scanf("%d", &q); while(q--) { scanf("%d%d", &n, &k); printf("%d\n",solve(n, k)); } } |