[Codeforces521E] Thematic Contests(贪心)

赛后4min过题的感觉真不爽啊……

题目链接:http://codeforces.com/contest/1077/problem/E

题意:要$n$个题出比赛,每一个题有一个类型$a_i$,要求每一天出的比赛都是同一种类型的题,并且每一种类型在这几天内只出现一次,并且当前一天出题数是前一天的2倍,问这些天最多出多少题。

首先维护一下每一种题出现的次数,我们只需要操作这个次数就可以了。

对题目出现次数从大到小排个序,接下来我们考虑枚举题目的上界,然后往下枚举就行了。

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
#include <bits/stdc++.h>
using namespace std;

using LL = long long;
const LL maxn = 200100;
map<LL,LL> vis;
LL n;

signed main() {
// freopen("in", "r", stdin);
LL a;
while(~scanf("%I64d", &n)) {
vis.clear();
for(LL i = 1; i <= n; i++) {
scanf("%I64d", &a);
vis[a]++;
}
vector<LL> cnt;
LL ret = 0;
for(auto x : vis) {
cnt.emplace_back(x.second);
ret = max(ret, x.second);
}
sort(cnt.begin(), cnt.end(), greater<int>());
for(int i = cnt[0]; i > 0; i--) {
LL t = i;
LL tmp = 0;
for(int j = 0; j < cnt.size(); j++) {
if(t & 1) {
if(cnt[j] >= t) tmp += t;
break;
}
if(cnt[j] < t) break;
tmp += t;
t >>= 1;
}
ret = max(ret, tmp);
}
printf("%I64d\n", ret);
}
return 0;
}