#include<cstdio> #include<iostream> #include<sstream> #include<cmath> #include<algorithm> #include<map> #include<set> #include<list> #include<vector> #include<stack> #include<queue> #include<string> #include<iomanip> #include<fstream> #include<ctime> using namespace std; typedef vector<int> VI; typedef pair <int,int> ii; typedef long long LL; #define pb push_back const int INF = 2147483647; const int M = 202000; int n, tab[M], maxx, i, x; int main() { scanf("%d", &n); while (n--) { scanf("%d", &x); tab[x]++; } maxx = 0; for (i=0;i<M-1;i++) { tab[i+1] += tab[i] / 2; if (tab[i] > 0) maxx = i; } printf("%d\n", maxx); }
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<cstdio> #include<iostream> #include<sstream> #include<cmath> #include<algorithm> #include<map> #include<set> #include<list> #include<vector> #include<stack> #include<queue> #include<string> #include<iomanip> #include<fstream> #include<ctime> using namespace std; typedef vector<int> VI; typedef pair <int,int> ii; typedef long long LL; #define pb push_back const int INF = 2147483647; const int M = 202000; int n, tab[M], maxx, i, x; int main() { scanf("%d", &n); while (n--) { scanf("%d", &x); tab[x]++; } maxx = 0; for (i=0;i<M-1;i++) { tab[i+1] += tab[i] / 2; if (tab[i] > 0) maxx = i; } printf("%d\n", maxx); } |