#include <bits/stdc++.h> #define int long long #define mp make_pair #define pb push_back #define ld long double #define pii pair<int,int> #define sz(x) (int)x.size() #define piii pair<pii,pii> #define precise cout<<fixed<<setprecision(10) #define st first #define nd second #define ins insert #define vi vector<int> #define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) using namespace std; const int MAX=105; vi P[MAX]; vi bits; vi wazne; vi pre; int32_t main(){ BOOST; int k; cin>>k; if (k==1){ cout<<"2\n"; cout<<"2 -1\n"; cout<<"-1 -1\n"; return 0; } for (int i=30;i>=0;i--){ if (k&(1<<i)){ bits.pb(i); } } int cnt=0; for (int i=1;i<=sz(bits)-1;i++){ pre.pb(++cnt); P[cnt].pb(cnt+1); } int highest=bits[0]; wazne.pb(++cnt); for (int i=1;i<=highest;i++){ int a=cnt; int b=cnt+1; int c=cnt+2; P[a].pb(c); P[a].pb(b); P[b].pb(c); wazne.pb(cnt+2); cnt+=2; } int teraz=1; for (int i=1;i<sz(bits);i++){ int xd=bits[i]; //cout<<"HAHA "<<xd<<"\n"; P[teraz++].pb(wazne[sz(wazne)-1-xd]); } for (int i=1;i<=cnt;i++)while (sz(P[i])<2)P[i].pb(-1); cout<<cnt<<"\n"; for (int i=1;i<=cnt;i++){ for (auto it:P[i])cout<<it<<" "; cout<<"\n"; } 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 | #include <bits/stdc++.h> #define int long long #define mp make_pair #define pb push_back #define ld long double #define pii pair<int,int> #define sz(x) (int)x.size() #define piii pair<pii,pii> #define precise cout<<fixed<<setprecision(10) #define st first #define nd second #define ins insert #define vi vector<int> #define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) using namespace std; const int MAX=105; vi P[MAX]; vi bits; vi wazne; vi pre; int32_t main(){ BOOST; int k; cin>>k; if (k==1){ cout<<"2\n"; cout<<"2 -1\n"; cout<<"-1 -1\n"; return 0; } for (int i=30;i>=0;i--){ if (k&(1<<i)){ bits.pb(i); } } int cnt=0; for (int i=1;i<=sz(bits)-1;i++){ pre.pb(++cnt); P[cnt].pb(cnt+1); } int highest=bits[0]; wazne.pb(++cnt); for (int i=1;i<=highest;i++){ int a=cnt; int b=cnt+1; int c=cnt+2; P[a].pb(c); P[a].pb(b); P[b].pb(c); wazne.pb(cnt+2); cnt+=2; } int teraz=1; for (int i=1;i<sz(bits);i++){ int xd=bits[i]; //cout<<"HAHA "<<xd<<"\n"; P[teraz++].pb(wazne[sz(wazne)-1-xd]); } for (int i=1;i<=cnt;i++)while (sz(P[i])<2)P[i].pb(-1); cout<<cnt<<"\n"; for (int i=1;i<=cnt;i++){ for (auto it:P[i])cout<<it<<" "; cout<<"\n"; } return 0; } |