Thematic Contests -codeforce

题意

\(n(1 \leq n \leq 2 * 10^5)\)个问题,第\(i\)个问题对应的主题是\(a_i\)。现在要组织\(t\)场考试

  • \(t\)场考试的主题互不相同
  • 为考试选取的问题的主题必须是该场考试的主题
  • 每场考试选取的问题个数必须是上一场考试选取的问题个数的两倍

题解

统计每个主题出现的次数,然后从小到大排序。因为每场考试的问题个数是上一场问题个数的2倍,所以\(t \leq 32\)。怎么确定第一场考试的题目数\(x\),因为\(t\)场考试的题目数是满足:\(x, 2x, 2^2x,2^3x,...,2^{t - 1}x\),所以用对应的考试题数,试除\(2^i\),取得最小值就是\(x\)

代码

const int N = 200005;

int n;
int a[N], b[N];

int qpow(int x, int tt) {
    int c = 1;
    for (; tt; x = x * x, tt >>= 1) if (tt & 1) c = c * x;
    return c;
}

map<int, int> use;
map<int, bool> vis;

int main()
{

    cin >> n;
    Rep(i, 1, n) cin >> a[i], use[a[i]]++;

    int t = 0;
    Rep(i, 1, n) if (!vis[a[i]]) {
        vis[a[i]] = 1;
        b[++t] = use[a[i]];
    }

    sort(b + 1, b + t + 1);

    int cnt = 0, ans = b[t];
    for (int i = t - 1; i; --i) if (cnt <= 30) {
        cnt++;

        int res = INF32;
        for (int j = i, tot = 0; j <= t; ++j, ++tot) res = min(res, b[j] / qpow(2, tot));

        ans = max(ans, res * (qpow(2, t - i + 1) - 1));
    }

    cout << ans << endl;
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/zgglj-com/p/9973963.html
今日推荐