#include<iostream> #include<vector> #define mp make_pair #define fi first #define se second using namespace std; const int N = 101; vector<int>v[N]; int n, k; int main() { ios_base::sync_with_stdio(0); cin >> k; if (k == 1) { cout << "2\n2 -1\n-1 -1\n"; return 0; } while (k > 1) { if (k % 2) { v[n].push_back(n + 1); v[n].push_back(N); n++; } k /= 2; if (k > 0) { v[n].push_back(n + 1); v[n].push_back(n + 2); n++; v[n].push_back(n + 1); n++; } } cout << n + 1 << endl; for (int i = 0; i <= n; i++) { for (int j = 0; j < 2; j++) { if (v[i].size() <= j) { cout << "-1"; } else { if (v[i][j] == N) { cout << n + 1; } else { cout << v[i][j] + 1; } } cout << " "; } cout << endl; } return 0; }
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 | #include<iostream> #include<vector> #define mp make_pair #define fi first #define se second using namespace std; const int N = 101; vector<int>v[N]; int n, k; int main() { ios_base::sync_with_stdio(0); cin >> k; if (k == 1) { cout << "2\n2 -1\n-1 -1\n"; return 0; } while (k > 1) { if (k % 2) { v[n].push_back(n + 1); v[n].push_back(N); n++; } k /= 2; if (k > 0) { v[n].push_back(n + 1); v[n].push_back(n + 2); n++; v[n].push_back(n + 1); n++; } } cout << n + 1 << endl; for (int i = 0; i <= n; i++) { for (int j = 0; j < 2; j++) { if (v[i].size() <= j) { cout << "-1"; } else { if (v[i][j] == N) { cout << n + 1; } else { cout << v[i][j] + 1; } } cout << " "; } cout << endl; } return 0; } |