#include<iostream>
#include<map>
#include<vector>
using namespace std;
long long k;
map<int, long long> fib;
vector<int> nodes;
void create_fib(){
fib[1] = 1;
fib[2] = 1;
for(int i=3; i<=45; i++){
fib[i] = fib[i-1] + fib[i-2];
}
}
void split_fib(){
int i = 45;
while(k>0){
if(k>=fib[i]){
k-=fib[i];
nodes.push_back(i);
}
i--;
}
}
void create_tree(){
for(int i=0; i<nodes[0]; i++){
if(i+1<nodes[0]){
cout << i+3 << " ";
}else{
cout << nodes[0] + nodes.size() + 2 << " ";
}
if(i+2<nodes[0]){
cout << i+4 << " ";
}else{
cout << -1 << " ";
}
cout << "\n";
}
}
void magistral(){
for(int i=0; i<nodes.size(); i++){
cout << (nodes[0]+2) - nodes[i] << " ";
if(i+1<nodes.size()){
cout << nodes[0] + 3 + i;
}else{
cout << -1;
}
cout << endl;
}
}
int main(){
cin >> k;
create_fib();
split_fib();
cout << nodes[0] + nodes.size() + 2 << "\n";
cout<< nodes[0] + 2 << " -1\n";
create_tree();
magistral();
cout << -1 << " " << -1 <<"\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 | #include<iostream> #include<map> #include<vector> using namespace std; long long k; map<int, long long> fib; vector<int> nodes; void create_fib(){ fib[1] = 1; fib[2] = 1; for(int i=3; i<=45; i++){ fib[i] = fib[i-1] + fib[i-2]; } } void split_fib(){ int i = 45; while(k>0){ if(k>=fib[i]){ k-=fib[i]; nodes.push_back(i); } i--; } } void create_tree(){ for(int i=0; i<nodes[0]; i++){ if(i+1<nodes[0]){ cout << i+3 << " "; }else{ cout << nodes[0] + nodes.size() + 2 << " "; } if(i+2<nodes[0]){ cout << i+4 << " "; }else{ cout << -1 << " "; } cout << "\n"; } } void magistral(){ for(int i=0; i<nodes.size(); i++){ cout << (nodes[0]+2) - nodes[i] << " "; if(i+1<nodes.size()){ cout << nodes[0] + 3 + i; }else{ cout << -1; } cout << endl; } } int main(){ cin >> k; create_fib(); split_fib(); cout << nodes[0] + nodes.size() + 2 << "\n"; cout<< nodes[0] + 2 << " -1\n"; create_tree(); magistral(); cout << -1 << " " << -1 <<"\n"; } |
English