#include <cstdio> #include <map> int main() { int n, tmp; std::map<int, long long> A; std::scanf("%d", &n); for(int i = 0; i < n; i++) { std::scanf("%d", &tmp); std::map<int, long long>::iterator it = A.find(tmp); if(it != A.end()) it->second += 1; else A[tmp] = 1; } for(std::map<int, long long>::iterator it = A.begin(); it != A.end(); it++) { if(it->second > 1) { std::map<int, long long>::iterator push_to = A.find(it->first + 1); if(push_to == A.end()) A[it->first + 1] = it->second / 2; else push_to->second += it->second / 2; } } std::map<int, long long>::iterator last = A.end(); last--; std::printf("%d\n", last->first); 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 | #include <cstdio> #include <map> int main() { int n, tmp; std::map<int, long long> A; std::scanf("%d", &n); for(int i = 0; i < n; i++) { std::scanf("%d", &tmp); std::map<int, long long>::iterator it = A.find(tmp); if(it != A.end()) it->second += 1; else A[tmp] = 1; } for(std::map<int, long long>::iterator it = A.begin(); it != A.end(); it++) { if(it->second > 1) { std::map<int, long long>::iterator push_to = A.find(it->first + 1); if(push_to == A.end()) A[it->first + 1] = it->second / 2; else push_to->second += it->second / 2; } } std::map<int, long long>::iterator last = A.end(); last--; std::printf("%d\n", last->first); return 0; } |