Codeforces Round #524 (Div.2)题解

Posted little-sun0331

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #524 (Div.2)题解相关的知识,希望对你有一定的参考价值。

题解 CF1080A 【Petya and Origami】

这道题其实要我们求的就是
[lceil 2*n/k ceil + lceil 5*n/k ceil + lceil 2*n/k ceil]
然后就做完了

# include <bits/stdc++.h>

# define ll long long

int main()
{
    ll n, k;
    scanf("%lld%lld", &n, &k);
    ll ans = ((2 * n) / k) + ((5 * n) / k) + ((8 * n) / k) + bool((2 * n) % k != 0) + bool((5 * n) % k != 0) + bool((8 * n) % k != 0);
    printf("%lld
", ans);
    return 0;
}

题解 CF1080B 【Margarite and the best present】

这道题其实求的是区间内偶数和减去奇数和

用等差数列求和公式即可

注意区间长度要(+1)

# include <bits/stdc++.h>

# define ll long long

int main()
{
    int q;
    scanf("%d", &q);
    while(q--)
    {
        ll l, r;
        ll ans;
        scanf("%I64d%I64d", &l, &r);
        if(l == r)
        {
            printf("%I64d
", ((l % 2) ? -l : l));
            continue;
        }
        ll x, y;
        ll lodd = ((l % 2 == 1) ? l : l + 1), leven = ((l % 2 == 0) ? l : l + 1), rodd = ((r % 2 == 1) ? r : r - 1), reven = ((r % 2 == 0) ? r : r - 1);
       
        x = ((reven - leven) / 2 + 1) * ((reven + leven) / 2);
        y = ((rodd - lodd) / 2 + 1) * ((rodd + lodd) / 2);
        //printf("%d %d %d %d
", leven, lodd, reven, rodd);
        ans = x - y;
        printf("%I64d
", ans);
    }
    return 0;
}

题解 CF1080C 【Masha and two friends】

这道题要注意的细节超级多,是一道分类讨论好题

其实这道题要求的就是

白色:原白色面积(+)矩形((x1, y1, x2, y2))中的黑色面积-矩形((x3, y3, x4, y4))中白色面积-矩形((x1, y1, x2, y2))与矩形((x3, y3, x4, y4))交集中的白色面积(注:本处的黑/白色面积指原矩形中的黑/白面积)

黑色:总面积-白色

好了做完了

(注意:左下角为黑色的矩形中白色的个数为(lfloor frac{n*m}2 floor),左下角为白色的矩形中白色的个数为(lceil frac{n*m}2 ceil)
Code:

#include <bits/stdc++.h>

#define ll long long

int main()
{
    int T;
    scanf("%d", &T);
    while (T--)
    {
        ll n, m;
        ll x[10], y[10];
        scanf("%I64d%I64d", &n, &m);
        for (int i = 1; i <= 4; i++)
            scanf("%I64d%I64d", &x[i], &y[i]), std::swap(x[i], y[i]);
        ll w = (n * m + 1) / 2, b = (n * m) - w;
        ll c1 = (x[2] - x[1] + 1) * (y[2] - y[1] + 1) - (((x[2] - x[1] + 1) * (y[2] - y[1] + 1) + ((x[1] % 2) == (y[1] % 2))) / 2);
        w += c1, b -= c1;
        ll c2 = (((x[4] - x[3] + 1) * (y[4] - y[3] + 1) + ((x[3] % 2) == (y[3] % 2))) / 2);
        w -= c2, b += c2;
        ll c3 = 0;
        if (((std::min(x[2], x[4]) >= std::max(x[1], x[3])) && ((std::min(y[2], y[4]) >= std::max(y[1], y[3])))))
            c3 = ((std::min(x[2], x[4]) - std::max(x[1], x[3]) + 1) * (std::min(y[2], y[4]) - std::max(y[1], y[3]) + 1)) - ((((std::min(x[2], x[4]) - std::max(x[1], x[3]) + 1) * (std::min(y[2], y[4]) - std::max(y[1], y[3]) + 1))) + ((std::max(x[1], x[3]) % 2) == (std::max(y[1], y[3]) % 2))) / 2;
        c3 = std::max(c3, 0ll);
        w -= c3, b += c3;
        printf("%I64d %I64d
", w, b);
    }
    return 0;
}



以上是关于Codeforces Round #524 (Div.2)题解的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #524 (Div. 2) codeforces 1080A~1080F

Codeforces Round #524 (Div.2)题解

Codeforces Round #524 (Div. 2)

Codeforces Round #524 Div. 2 翻车记

Codeforces Round #524 (Div. 2)(前3题题解)

Codeforces Round #524 (Div. 2) F