#include <iostream> #include <cstdlib> using namespace std; int tab[500001], n; int compare(const void* a, const void* b) { const int* x = (int*) a; const int* y = (int*) b; if (*x < *y) return 1; else if (*x > *y) return -1; return 0; } int main() { int i, x; std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); cin >> n; for (i = 0; i < n; i++) { cin >> x; tab[x]++; } qsort(tab,n + 1,sizeof(int),compare); i = 0; while (1) { if (tab[i] + tab[i] > n) { cout << (i + 1); return 0; } n = n - tab[i] - tab[i] + 1; 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 | #include <iostream> #include <cstdlib> using namespace std; int tab[500001], n; int compare(const void* a, const void* b) { const int* x = (int*) a; const int* y = (int*) b; if (*x < *y) return 1; else if (*x > *y) return -1; return 0; } int main() { int i, x; std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); cin >> n; for (i = 0; i < n; i++) { cin >> x; tab[x]++; } qsort(tab,n + 1,sizeof(int),compare); i = 0; while (1) { if (tab[i] + tab[i] > n) { cout << (i + 1); return 0; } n = n - tab[i] - tab[i] + 1; i++; } return 0; } |