#include <iostream> using namespace std; const int MAX_TABLE = 1000000; const int MAX_HALF = 500000; const int MAX_POWER = 32; int Monety[ MAX_TABLE ]; int Power2[ MAX_POWER ]; int Table [ MAX_POWER ]; void PowerOf2(){ int oPower=1; for(int oLoop=1; oLoop<MAX_POWER; oLoop++){ Power2[oLoop]=oPower; oPower*=2; } } void BinToTable(int aValue){ int oIter=0; while(aValue!=0){ Table[oIter++] = aValue%2; aValue /= 2; } for(int oLoop=oIter;oLoop<MAX_POWER;oLoop++){ Table[oLoop]=0; } } void Compute(int aPos){ for(int oLoop=0; oLoop < MAX_POWER; oLoop++ ){ Monety[aPos+oLoop]+=Table[oLoop]; } } void PrintTable(){ for(int oLoop=0;oLoop<50;oLoop++){ cout<<Monety[oLoop]; } cout<<endl; } int main() { int oBorder; int oMoneta; for(int oLoop=0; oLoop<MAX_TABLE; oLoop++){ Monety[oLoop]=0; } cin >> oBorder; for(int oLoop=0; oLoop < oBorder; oLoop++ ){ cin >> oMoneta; Monety[oMoneta]++; } for(int oLoop=0; oLoop < MAX_HALF+1; oLoop++){ BinToTable(Monety[oLoop]); Monety[oLoop]=0; Compute(oLoop); //PrintTable(); } for(int oLoop=MAX_HALF; oLoop >= 0; oLoop--){ if(Monety[oLoop]!=0){ oBorder=oLoop; break; } } cout << oBorder << 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | #include <iostream> using namespace std; const int MAX_TABLE = 1000000; const int MAX_HALF = 500000; const int MAX_POWER = 32; int Monety[ MAX_TABLE ]; int Power2[ MAX_POWER ]; int Table [ MAX_POWER ]; void PowerOf2(){ int oPower=1; for(int oLoop=1; oLoop<MAX_POWER; oLoop++){ Power2[oLoop]=oPower; oPower*=2; } } void BinToTable(int aValue){ int oIter=0; while(aValue!=0){ Table[oIter++] = aValue%2; aValue /= 2; } for(int oLoop=oIter;oLoop<MAX_POWER;oLoop++){ Table[oLoop]=0; } } void Compute(int aPos){ for(int oLoop=0; oLoop < MAX_POWER; oLoop++ ){ Monety[aPos+oLoop]+=Table[oLoop]; } } void PrintTable(){ for(int oLoop=0;oLoop<50;oLoop++){ cout<<Monety[oLoop]; } cout<<endl; } int main() { int oBorder; int oMoneta; for(int oLoop=0; oLoop<MAX_TABLE; oLoop++){ Monety[oLoop]=0; } cin >> oBorder; for(int oLoop=0; oLoop < oBorder; oLoop++ ){ cin >> oMoneta; Monety[oMoneta]++; } for(int oLoop=0; oLoop < MAX_HALF+1; oLoop++){ BinToTable(Monety[oLoop]); Monety[oLoop]=0; Compute(oLoop); //PrintTable(); } for(int oLoop=MAX_HALF; oLoop >= 0; oLoop--){ if(Monety[oLoop]!=0){ oBorder=oLoop; break; } } cout << oBorder << endl; return 0; } |