#include <iostream> #include <math.h> #include <stdio.h> #include <string> #include <map> #include <stdlib.h> #include <vector> #include <cstring> #include <algorithm> using namespace std; class Node { public: int ownNumber; int target1; int target2; Node(int nubmer, int t1, int t2) { target1 = t1; target2 = t2; ownNumber = nubmer; } }; int main() { int edges = 15; scanf("%d", &edges); vector<Node> map; map.push_back(Node(0, -1, -1)); for (int i = 1; i < 30; i++) { map.push_back(Node(i, i + 1, -1)); } map.push_back(Node(30, 31, -1)); int expectedTowerElements = 28 * 2 + 3; map.push_back(Node(31, 32 + expectedTowerElements, -1)); int towerElements = 3; map.push_back(Node(32, 30, 31)); map.push_back(Node(33, 30, 31)); map.push_back(Node(34, 32, 33)); for (int j = 0 ; j < 28; j++) { map.push_back(Node(32 + towerElements, 29 + towerElements, 30 + towerElements)); map.push_back(Node(33 + towerElements, 31 + towerElements , 32 + towerElements)); towerElements++; towerElements++; } edges--; int currentNode = 1; for (int i = 0 ; i < 31; i++){ int bit = (edges >> i) & 1; if (bit == 1) { if (i == 0) { map[currentNode].target2 = 33 + towerElements; currentNode++; } else { map[currentNode].target2 = 33 + (i - 1) * 2; currentNode++; } } } map.push_back(Node(32, 33 + towerElements, -1)); map.push_back(Node(33 + towerElements, -1, -1)); printf("%d\n", map.size() - 1); for (int i = 1 ; i < map.size(); i++){ printf("%d %d\n", map[i].target1, map[i].target2); } 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | #include <iostream> #include <math.h> #include <stdio.h> #include <string> #include <map> #include <stdlib.h> #include <vector> #include <cstring> #include <algorithm> using namespace std; class Node { public: int ownNumber; int target1; int target2; Node(int nubmer, int t1, int t2) { target1 = t1; target2 = t2; ownNumber = nubmer; } }; int main() { int edges = 15; scanf("%d", &edges); vector<Node> map; map.push_back(Node(0, -1, -1)); for (int i = 1; i < 30; i++) { map.push_back(Node(i, i + 1, -1)); } map.push_back(Node(30, 31, -1)); int expectedTowerElements = 28 * 2 + 3; map.push_back(Node(31, 32 + expectedTowerElements, -1)); int towerElements = 3; map.push_back(Node(32, 30, 31)); map.push_back(Node(33, 30, 31)); map.push_back(Node(34, 32, 33)); for (int j = 0 ; j < 28; j++) { map.push_back(Node(32 + towerElements, 29 + towerElements, 30 + towerElements)); map.push_back(Node(33 + towerElements, 31 + towerElements , 32 + towerElements)); towerElements++; towerElements++; } edges--; int currentNode = 1; for (int i = 0 ; i < 31; i++){ int bit = (edges >> i) & 1; if (bit == 1) { if (i == 0) { map[currentNode].target2 = 33 + towerElements; currentNode++; } else { map[currentNode].target2 = 33 + (i - 1) * 2; currentNode++; } } } map.push_back(Node(32, 33 + towerElements, -1)); map.push_back(Node(33 + towerElements, -1, -1)); printf("%d\n", map.size() - 1); for (int i = 1 ; i < map.size(); i++){ printf("%d %d\n", map[i].target1, map[i].target2); } return 0; } |