#include <iostream> #include <vector> int main() { int32_t k; std::cin >> k; std::vector<bool> to_1; std::vector<bool> to_2; std::vector<bool> to_end; if (k == 1) { // nasty special case to_1.push_back(true); to_2.push_back(false); to_end.push_back(false); } while (k > 1) { if (k == 3) { // another nasty special case to_1.push_back(true); to_2.push_back(false); to_end.push_back(true); k -= 1; } to_1.push_back(true); to_2.push_back(true); to_end.push_back(false); to_1.push_back(false); to_2.push_back(true); if (k % 2 == 1) { to_end.push_back(true); k -= 1; } else { to_end.push_back(false); } to_1.push_back(true); to_2.push_back(false); to_end.push_back(false); k /= 2; } to_1.push_back(false); to_2.push_back(false); to_end.push_back(false); std::cout << to_1.size() << "\n"; for (int32_t i = 0; i < (int32_t)to_1.size(); ++i) { int32_t left = 2; if (to_1[i]) { left -= 1; std::cout << i + 2 << " "; } if (to_2[i]) { left -= 1; std::cout << i + 3 << " "; } if (to_end[i]) { left -= 1; std::cout << to_1.size() << " "; } switch (left) { case 2: std::cout << "-1 "; // fallthrough case 1: std::cout << "-1 "; } std::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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | #include <iostream> #include <vector> int main() { int32_t k; std::cin >> k; std::vector<bool> to_1; std::vector<bool> to_2; std::vector<bool> to_end; if (k == 1) { // nasty special case to_1.push_back(true); to_2.push_back(false); to_end.push_back(false); } while (k > 1) { if (k == 3) { // another nasty special case to_1.push_back(true); to_2.push_back(false); to_end.push_back(true); k -= 1; } to_1.push_back(true); to_2.push_back(true); to_end.push_back(false); to_1.push_back(false); to_2.push_back(true); if (k % 2 == 1) { to_end.push_back(true); k -= 1; } else { to_end.push_back(false); } to_1.push_back(true); to_2.push_back(false); to_end.push_back(false); k /= 2; } to_1.push_back(false); to_2.push_back(false); to_end.push_back(false); std::cout << to_1.size() << "\n"; for (int32_t i = 0; i < (int32_t)to_1.size(); ++i) { int32_t left = 2; if (to_1[i]) { left -= 1; std::cout << i + 2 << " "; } if (to_2[i]) { left -= 1; std::cout << i + 3 << " "; } if (to_end[i]) { left -= 1; std::cout << to_1.size() << " "; } switch (left) { case 2: std::cout << "-1 "; // fallthrough case 1: std::cout << "-1 "; } std::cout << "\n"; } } |