#include <bits/stdc++.h> using namespace std; typedef long long LL; const int MAXN = 128; int main() { ios::sync_with_stdio(false); cin.tie(0); vector<int> g[MAXN]; int k; cin >> k; int n = 1; while (true) { if (k % 2 == 1) { g[n].push_back(n + 1); g[n].push_back(-1); n = n + 1; } k /= 2; if (k <= 0) break; g[n].push_back(n + 1); g[n].push_back(n + 2); g[n + 1].push_back(n + 2); n = n + 2; } for (int i = 1; i <= n; ++i) { for (int j = 0; j < (int) g[i].size(); ++j) { if (g[i][j] == -1) g[i][j] = n + 1; } } cout << n + 1 << "\n"; for (int i = 1; i <= n + 1; ++i) { while (g[i].size() < 2) g[i].push_back(-1); for (int v : g[i]) cout << v << " "; cout << "\n"; } }
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 | #include <bits/stdc++.h> using namespace std; typedef long long LL; const int MAXN = 128; int main() { ios::sync_with_stdio(false); cin.tie(0); vector<int> g[MAXN]; int k; cin >> k; int n = 1; while (true) { if (k % 2 == 1) { g[n].push_back(n + 1); g[n].push_back(-1); n = n + 1; } k /= 2; if (k <= 0) break; g[n].push_back(n + 1); g[n].push_back(n + 2); g[n + 1].push_back(n + 2); n = n + 2; } for (int i = 1; i <= n; ++i) { for (int j = 0; j < (int) g[i].size(); ++j) { if (g[i][j] == -1) g[i][j] = n + 1; } } cout << n + 1 << "\n"; for (int i = 1; i <= n + 1; ++i) { while (g[i].size() < 2) g[i].push_back(-1); for (int v : g[i]) cout << v << " "; cout << "\n"; } } |