#include <bits/stdc++.h> #define fi first #define se second #define pb push_back using namespace std; typedef long long ll; typedef pair<int, int> pii; const int maxn = 2005; vector<int> graph[105]; int main() { ios_base::sync_with_stdio(0); int k; cin >> k; int last = 100; for (int i = 0; i < 30; i++) { graph[last - 1].push_back(last); graph[last - 2].push_back(last - 1); graph[last - 2].push_back(last); last -= 2; } int cur = 1; int pot = 0; while (k > 0) { if (k % 2 == 1) { graph[cur].push_back(100 - pot * 2); graph[cur].push_back(cur + 1); cur++; } k /= 2; pot++; } cout << 100 << "\n"; for (int i = 1; i <= 100; i++) { assert(graph[i].size() <= 2); if (graph[i].size() == 0) cout << "-1 -1\n"; if (graph[i].size() == 1) cout << graph[i][0] << " -1\n"; if (graph[i].size() == 2) cout << graph[i][0] << " " << graph[i][1] << "\n"; } 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 | #include <bits/stdc++.h> #define fi first #define se second #define pb push_back using namespace std; typedef long long ll; typedef pair<int, int> pii; const int maxn = 2005; vector<int> graph[105]; int main() { ios_base::sync_with_stdio(0); int k; cin >> k; int last = 100; for (int i = 0; i < 30; i++) { graph[last - 1].push_back(last); graph[last - 2].push_back(last - 1); graph[last - 2].push_back(last); last -= 2; } int cur = 1; int pot = 0; while (k > 0) { if (k % 2 == 1) { graph[cur].push_back(100 - pot * 2); graph[cur].push_back(cur + 1); cur++; } k /= 2; pot++; } cout << 100 << "\n"; for (int i = 1; i <= 100; i++) { assert(graph[i].size() <= 2); if (graph[i].size() == 0) cout << "-1 -1\n"; if (graph[i].size() == 1) cout << graph[i][0] << " -1\n"; if (graph[i].size() == 2) cout << graph[i][0] << " " << graph[i][1] << "\n"; } return 0; } |