#include <iostream> #include <vector> #include <algorithm> #include <cstring> using namespace std; #define REP(i,n) for(int i=0; i<(n); i++) int n; vector<int> adj[110]; void calc(int s, int t, int k) { if(k % 2 == 1 && s != t) adj[s].push_back(t); if(k == 1) return; adj[s].push_back(s+1); adj[t-2].push_back(t-1); adj[t-2].push_back(t); adj[t-1].push_back(t); calc(s+1, t-2, k/2); } int main() { int k; cin >> k; if(k == 1) { n = 2; } else { n = 1; int kk=k; while(kk > 1) { kk /= 2; n += 3; } } calc(0, n-1, k); cout << n << endl; REP(i,n) { while(adj[i].size() < 2) adj[i].push_back(-1); REP(j,2) { if(adj[i][j] > -1) adj[i][j]++; cout << adj[i][j] << " "; } cout << endl; } 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 | #include <iostream> #include <vector> #include <algorithm> #include <cstring> using namespace std; #define REP(i,n) for(int i=0; i<(n); i++) int n; vector<int> adj[110]; void calc(int s, int t, int k) { if(k % 2 == 1 && s != t) adj[s].push_back(t); if(k == 1) return; adj[s].push_back(s+1); adj[t-2].push_back(t-1); adj[t-2].push_back(t); adj[t-1].push_back(t); calc(s+1, t-2, k/2); } int main() { int k; cin >> k; if(k == 1) { n = 2; } else { n = 1; int kk=k; while(kk > 1) { kk /= 2; n += 3; } } calc(0, n-1, k); cout << n << endl; REP(i,n) { while(adj[i].size() < 2) adj[i].push_back(-1); REP(j,2) { if(adj[i][j] > -1) adj[i][j]++; cout << adj[i][j] << " "; } cout << endl; } return 0; } |