#include <iostream> #include <list> using namespace std; int main(){ // Jakub Wasilewski (nazwa konta rekrer) std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int reqBits; cin >> reqBits; int bits = 0; int nums = 0; while (bits < reqBits){ nums+=1; int actNum = nums; for(int i = 1; i <= 25; i++){ bits += actNum%2; actNum>>=1; } } int numToCheck = nums; int deletenNumsAmount = 0; list<int> deletedNums; while(bits > reqBits){ int bitsInNum = 0; int actNum = numToCheck; for(int i = 1; i <= 20; i++){ bitsInNum += actNum%2; actNum>>=1; } if(bitsInNum<=(bits-reqBits)){ deletedNums.push_front(numToCheck); bits-=bitsInNum; deletenNumsAmount+=1; } numToCheck-=1; } cout<< nums - deletenNumsAmount << "\n"; //int numToDelete = deletedNums.back(); //deletedNums.pop_back(); //for(int i = 1; i <= nums; i++){ // if(numToDelete == i){ // if(deletedNums.size()>0){ // numToDelete = deletedNums.back(); // deletedNums.pop_back(); // } // }else{ // cout << i << " "; // } //} int numToDelete = -1; if(deletedNums.size()>0){ numToDelete = deletedNums.front(); deletedNums.pop_front(); } for(int i = nums; i > 0; i--){ if(numToDelete == i){ if(deletedNums.size()>0){ numToDelete = deletedNums.front(); deletedNums.pop_front(); } }else{ cout << i << " "; } } 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 | #include <iostream> #include <list> using namespace std; int main(){ // Jakub Wasilewski (nazwa konta rekrer) std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int reqBits; cin >> reqBits; int bits = 0; int nums = 0; while (bits < reqBits){ nums+=1; int actNum = nums; for(int i = 1; i <= 25; i++){ bits += actNum%2; actNum>>=1; } } int numToCheck = nums; int deletenNumsAmount = 0; list<int> deletedNums; while(bits > reqBits){ int bitsInNum = 0; int actNum = numToCheck; for(int i = 1; i <= 20; i++){ bitsInNum += actNum%2; actNum>>=1; } if(bitsInNum<=(bits-reqBits)){ deletedNums.push_front(numToCheck); bits-=bitsInNum; deletenNumsAmount+=1; } numToCheck-=1; } cout<< nums - deletenNumsAmount << "\n"; //int numToDelete = deletedNums.back(); //deletedNums.pop_back(); //for(int i = 1; i <= nums; i++){ // if(numToDelete == i){ // if(deletedNums.size()>0){ // numToDelete = deletedNums.back(); // deletedNums.pop_back(); // } // }else{ // cout << i << " "; // } //} int numToDelete = -1; if(deletedNums.size()>0){ numToDelete = deletedNums.front(); deletedNums.pop_front(); } for(int i = nums; i > 0; i--){ if(numToDelete == i){ if(deletedNums.size()>0){ numToDelete = deletedNums.front(); deletedNums.pop_front(); } }else{ cout << i << " "; } } return 0; } |