#include <bits/stdc++.h> using namespace std; int main(){ int k; cin >> k; int n=99; vector <int> v[n]; int maks=0; for (int i=0; i<30;i++){ if((k & (1<<i))){ maks=i; } } int poz=0; for (int i=0; i<n;i++){ v[i].push_back(i+1); } for (int i=0; i<2*maks;i+=2){ v[i].push_back(i+2); } for (int i=0; i<maks;i++){ if((k & (1<<i))){ v[2*i+1].push_back(n-1); } } v[n-1].clear(); cout << n<<endl; for (int i=0; i<n;i++){ for (int j=0; j<2;j++){ if (j<v[i].size()){ cout << v[i][j]+1<<" "; }else{ cout << -1<<" "; } } cout << endl; } }
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 | #include <bits/stdc++.h> using namespace std; int main(){ int k; cin >> k; int n=99; vector <int> v[n]; int maks=0; for (int i=0; i<30;i++){ if((k & (1<<i))){ maks=i; } } int poz=0; for (int i=0; i<n;i++){ v[i].push_back(i+1); } for (int i=0; i<2*maks;i+=2){ v[i].push_back(i+2); } for (int i=0; i<maks;i++){ if((k & (1<<i))){ v[2*i+1].push_back(n-1); } } v[n-1].clear(); cout << n<<endl; for (int i=0; i<n;i++){ for (int j=0; j<2;j++){ if (j<v[i].size()){ cout << v[i][j]+1<<" "; }else{ cout << -1<<" "; } } cout << endl; } } |