#include <bits/stdc++.h>
using namespace std;
struct TestCase
{
int path_count;
};
TestCase read_test_case();
void solve_test_case(const TestCase&);
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve_test_case(read_test_case());
}
TestCase read_test_case()
{
TestCase test_case;
cin >> test_case.path_count;
return test_case;
}
struct Node
{
int first, second;
};
void solve_test_case(const TestCase& test_case)
{
vector<Node> nodes;
for (int i = 1; (1 << ((i - 1) / 2)) <= test_case.path_count; i++)
{
if (i % 2 == 1)
nodes.push_back({i + 1, i + 2});
else
nodes.push_back({i + 1, -1});
}
// Last two nodes here are kinda special
nodes[nodes.size() - 1].first = -1;
nodes[nodes.size() - 2].second = -1;
nodes.push_back({-1, -1});
int last_node = nodes.size();
int k = test_case.path_count;
for (int i = 0; (1 << i) <= test_case.path_count; i++)
{
if ((1 << i) & k)
{
int index = 2 * i + 1;
nodes[index].second = last_node;
}
}
cout << last_node << "\n";
for (auto n : nodes) { cout << n.first << " " << n.second << "\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 62 | #include <bits/stdc++.h> using namespace std; struct TestCase { int path_count; }; TestCase read_test_case(); void solve_test_case(const TestCase&); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve_test_case(read_test_case()); } TestCase read_test_case() { TestCase test_case; cin >> test_case.path_count; return test_case; } struct Node { int first, second; }; void solve_test_case(const TestCase& test_case) { vector<Node> nodes; for (int i = 1; (1 << ((i - 1) / 2)) <= test_case.path_count; i++) { if (i % 2 == 1) nodes.push_back({i + 1, i + 2}); else nodes.push_back({i + 1, -1}); } // Last two nodes here are kinda special nodes[nodes.size() - 1].first = -1; nodes[nodes.size() - 2].second = -1; nodes.push_back({-1, -1}); int last_node = nodes.size(); int k = test_case.path_count; for (int i = 0; (1 << i) <= test_case.path_count; i++) { if ((1 << i) & k) { int index = 2 * i + 1; nodes[index].second = last_node; } } cout << last_node << "\n"; for (auto n : nodes) { cout << n.first << " " << n.second << "\n"; } } |
English