//runda 5C #include <iostream> #include <bitset> using namespace std; int wierz[2][150]; int main() { ios_base::sync_with_stdio(0); int k, iB, startBit, ostWiez; fill_n(wierz[0], 150, -1); fill_n(wierz[1], 150, -1); cin >> k; string binarka = bitset<32>(k).to_string(); iB = 0; while(binarka[iB] == '0') ++iB; startBit = 32 - iB; if(startBit == 1) { cout << 2 << endl; cout << "2 -1" << endl; cout << "-1 -1"; return 0; } ostWiez = (startBit - 1) * 3 +1; for(int i = 1; i < ostWiez; ++i) { wierz[0][i] = i + 1; if((i - 2) % 3 == 0) wierz[1][i] = i + 2; } for(int i = 1; i < startBit; ++i) if(binarka[32 - i] == '1') wierz[1][(i - 1) * 3 + 1] = ostWiez; cout << ostWiez << endl; for(int i = 1; i <= ostWiez; ++i) cout << wierz[0][i] << " " << wierz[1][i] << 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 | //runda 5C #include <iostream> #include <bitset> using namespace std; int wierz[2][150]; int main() { ios_base::sync_with_stdio(0); int k, iB, startBit, ostWiez; fill_n(wierz[0], 150, -1); fill_n(wierz[1], 150, -1); cin >> k; string binarka = bitset<32>(k).to_string(); iB = 0; while(binarka[iB] == '0') ++iB; startBit = 32 - iB; if(startBit == 1) { cout << 2 << endl; cout << "2 -1" << endl; cout << "-1 -1"; return 0; } ostWiez = (startBit - 1) * 3 +1; for(int i = 1; i < ostWiez; ++i) { wierz[0][i] = i + 1; if((i - 2) % 3 == 0) wierz[1][i] = i + 2; } for(int i = 1; i < startBit; ++i) if(binarka[32 - i] == '1') wierz[1][(i - 1) * 3 + 1] = ostWiez; cout << ostWiez << endl; for(int i = 1; i <= ostWiez; ++i) cout << wierz[0][i] << " " << wierz[1][i] << endl; return 0; } |