CF 281 div2 小记

problems: http://codeforces.com/contest/493

晚上11点开始的,只看了B和C,然后睡了,悲剧的是C一直没发现空间开小了,然后各种改都是WA,早上起来一看B又被黑了,然后发现long long的情况没处理。

B是水题,如果求和来判断第一种情况注意使用long long。

C题暴力:对每个可能成为最优解的d都求出a和b,然后更新即可。首先,对每个a[i], (a[i]-1, a[i],a[i]+1)这三个数都可以作为d,同样对b[i],构造一个c序列存放所有可能成为最优解的d。其次,对每个d如何求出aa和bb?其实只要对a[]和b[]排序,然后用upper_bound就行了,具体见下代码。

// C
# include <stdio.h>
# include <algorithm>
const int maxn = 200005;
int n, m, k;
int a[maxn], b[maxn];
int c[6*maxn+105];
const int inf = 0x7fffffff;
void add(int x)
{
    if (x < 0 ) return ;
    c[k++] = x;
}
int main()
{
    k = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]), add(a[i]-1), add(a[i]), add(a[i]+1);
    scanf("%d", &m);
    for (int i = 0; i < m; ++i) scanf("%d", &b[i]), add(b[i]-1), add(b[i]), add(b[i]+1);

    std::sort(a, a+n);
    std::sort(b, b+m);
    std::sort(c, c+k);
    int ans = -inf, aa, bb;

    for (int i = 0; i < k; ++i) {
        int ta = std::upper_bound(a, a+n, c[i]) - a;
        int tb = std::upper_bound(b, b+m, c[i]) - b;
        ta = ta*2 + (n-ta)*3;
        tb = tb*2 + (m-tb)*3;
        if (ans < ta - tb) {
            ans = ta - tb;
            aa = ta;
            bb = tb;
        } else if (ans == ta-tb && ta > aa) {
            aa = ta;
            bb = tb;
        }
    }

    printf("%d:%d
", aa, bb);

    return 0;
}
原文地址:https://www.cnblogs.com/txd0u/p/4142632.html