#include <cstdio> #include <utility> #include <vector> #include <algorithm> #include <string> using namespace std; void move_soldiers(vector<bool>& ready, vector<pair<int, int>>& commands) { for (auto& command : commands) { if (ready[command.first - 1] && !ready[command.second - 1]) { ready[command.first - 1] = false; ready[command.second - 1] = true; } } } bool check_soldiers(vector<bool>& ready, int k) { int left, right; for (int i = 0; i < ready.size(); i++) { if (ready[i]) { left = i; break; } } for (int i = ready.size() - 1; i >= 0; i--) { if (ready[i]) { right = ready.size() - i - 1; break; } } // printf("left: %d right: %d\n", left, right); return ready.size() - left - right == k; } int main() { int n, m; scanf("%d %d", &n, &m); vector<pair<int, int>> commands(m); for (int i = 0; i < m; i++) { int a, b; scanf("%d %d", &a, &b); commands[i] = make_pair(a, b); } for (int k = 1; k <= n; k++) { int result = 0; string bitmask(k, 1); bitmask.resize(n, 0); // printf("\n\nK: %d\n", k); do { vector<bool> ready(n, 0); for (int i = 0; i < n; ++i) { ready[i] = bitmask[i]; } // for (int i = 0; i < ready.size(); i++) { // printf("%c ", ready[i] ? 'R' : 'N'); // } // puts(""); move_soldiers(ready, commands); // for (int i = 0; i < ready.size(); i++) { // printf("%c ", ready[i] ? 'R' : 'N'); // } // puts(""); if (check_soldiers(ready, k)) { result = (result + 1) % 2; } } while (prev_permutation(bitmask.begin(), bitmask.end())); printf("%d ", result); } }
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | #include <cstdio> #include <utility> #include <vector> #include <algorithm> #include <string> using namespace std; void move_soldiers(vector<bool>& ready, vector<pair<int, int>>& commands) { for (auto& command : commands) { if (ready[command.first - 1] && !ready[command.second - 1]) { ready[command.first - 1] = false; ready[command.second - 1] = true; } } } bool check_soldiers(vector<bool>& ready, int k) { int left, right; for (int i = 0; i < ready.size(); i++) { if (ready[i]) { left = i; break; } } for (int i = ready.size() - 1; i >= 0; i--) { if (ready[i]) { right = ready.size() - i - 1; break; } } // printf("left: %d right: %d\n", left, right); return ready.size() - left - right == k; } int main() { int n, m; scanf("%d %d", &n, &m); vector<pair<int, int>> commands(m); for (int i = 0; i < m; i++) { int a, b; scanf("%d %d", &a, &b); commands[i] = make_pair(a, b); } for (int k = 1; k <= n; k++) { int result = 0; string bitmask(k, 1); bitmask.resize(n, 0); // printf("\n\nK: %d\n", k); do { vector<bool> ready(n, 0); for (int i = 0; i < n; ++i) { ready[i] = bitmask[i]; } // for (int i = 0; i < ready.size(); i++) { // printf("%c ", ready[i] ? 'R' : 'N'); // } // puts(""); move_soldiers(ready, commands); // for (int i = 0; i < ready.size(); i++) { // printf("%c ", ready[i] ? 'R' : 'N'); // } // puts(""); if (check_soldiers(ready, k)) { result = (result + 1) % 2; } } while (prev_permutation(bitmask.begin(), bitmask.end())); printf("%d ", result); } } |