#include <bits/stdc++.h> #define boost \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define ll long long #define st first #define nd second using namespace std; const int N(1e2 + 13); int n, q, k; vector<int> V[N]; int countBits(int k) { int bits = 0; while (k != 0) { bits++; k >>= 1; } return bits; } void initGraph() { for (int i = 1; i < n - 3; i += 3) { V[i].push_back(i + 1); V[i].push_back(i + 3); V[i + 1].push_back(i + 2); V[i + 1].push_back(i + 3); } V[n - 3].push_back(n); } void setGraph() { for (int i = 0; i < countBits(k) - 1; i++) { if ((1 << i) & k) { V[3 * (i + 1)].push_back(n); } } } void printGraph() { cout << n << endl; for (int i = 1; i <= n; i++) { if (V[i].size() > 0) { cout << V[i][0] << " "; if (V[i].size() > 1) { cout << V[i][1] << " "; } else { cout << "-1"; } } else { cout << "-1 -1"; } cout << endl; } } // int goThroughBits(int k) { // for (int i = 1; i <= countBits(k); i++) { // } // } int main() { boost; cin >> k; n = 3 * countBits(k) + 1; initGraph(); setGraph(); printGraph(); }
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 | #include <bits/stdc++.h> #define boost \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define ll long long #define st first #define nd second using namespace std; const int N(1e2 + 13); int n, q, k; vector<int> V[N]; int countBits(int k) { int bits = 0; while (k != 0) { bits++; k >>= 1; } return bits; } void initGraph() { for (int i = 1; i < n - 3; i += 3) { V[i].push_back(i + 1); V[i].push_back(i + 3); V[i + 1].push_back(i + 2); V[i + 1].push_back(i + 3); } V[n - 3].push_back(n); } void setGraph() { for (int i = 0; i < countBits(k) - 1; i++) { if ((1 << i) & k) { V[3 * (i + 1)].push_back(n); } } } void printGraph() { cout << n << endl; for (int i = 1; i <= n; i++) { if (V[i].size() > 0) { cout << V[i][0] << " "; if (V[i].size() > 1) { cout << V[i][1] << " "; } else { cout << "-1"; } } else { cout << "-1 -1"; } cout << endl; } } // int goThroughBits(int k) { // for (int i = 1; i <= countBits(k); i++) { // } // } int main() { boost; cin >> k; n = 3 * countBits(k) + 1; initGraph(); setGraph(); printGraph(); } |