Codeforces Round #524 (Div.2)题解

题解 CF1080A 【Petya and Origami】

这道题其实要我们求的就是

\[\lceil 2*n/k \rceil + \lceil 5*n/k \rceil + \lceil 2*n/k \rceil\]

然后就做完了

# 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\n", 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\n", ((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\n", leven, lodd, reven, rodd);
        ans = x - y;
        printf("%I64d\n", 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 \rfloor\),左下角为白色的矩形中白色的个数为\(\lceil \frac{n*m}2 \rceil\))

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\n", w, b);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/little-sun0331/p/10014591.html

时间: 2024-08-02 04:53:09

Codeforces Round #524 (Div.2)题解的相关文章

Codeforces Round #262 (Div. 2) 题解

A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When

Codeforces Round #FF (Div. 2) 题解

比赛链接:http://codeforces.com/contest/447 A. DZY Loves Hash time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output DZY has a hash table with p buckets, numbered from 0 to p?-?1. He wants to insert n 

Codeforces Round #259 (Div. 2) 题解

A. Little Pony and Crystal Mine time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size n (n is odd; n?>?1) is an n?×?n 

Codeforces Round #177 (Div. 2) 题解

[前言]咦?现在怎么流行打CF了?于是当一帮大爷在执着的打div 1的时候,我偷偷的在刷div 2.至于怎么决定场次嘛,一般我报一个数字A,随便再拉一个人选一个数字B.然后开始做第A^B场.如果觉得机密性不高,来点取模吧.然后今天做的这场少有的AK了.(其实模拟赛只做完了4题,最后1题来不及打了) 等等,话说前面几题不用写题解了?算了,让我难得风光一下啦. [A] A. Polo the Penguin and Segments time limit per test 2 seconds mem

Codeforces Round #534 (Div. 2)题解

Codeforces Round #534 (Div. 2)题解 A. Splitting into digits 题目大意 将一个数字分成几部分,几部分求和既是原数,问如何分可以使得分出来的各个数之间的差值尽可能小 解题思路 将n分成n个1相加即可 AC代码 #include<cstring> #include<string> #include<iostream> #include<cstdio> using namespace std; int main

Codeforces Round #561 (Div. 2) 题解

Codeforces Round #561 (Div. 2) 题解 题目链接 A. Silent Classroom 水题. Code #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 105; int n; char s[N], t[N]; int main() { cin >> n; for(int i = 1; i <= n; i++) { scanf(&q

Codeforces Round #608 (Div. 2) 题解

目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 程序 D. Portals 题意 做法 程序 E. Common Number 题意 做法 程序 结束语 Codeforces Round #608 (Div. 2) 题解 前言 题目链接:仅仅只是为了方便以题目作为关键字能查找到我的题解而已(逃 Codeforces 1271A Codeforce

Codeforces Round #617 (Div. 3) 题解

目录 Codeforces Round #617 (Div. 3) 题解 前言 A. Array with Odd Sum 题意 做法 程序 B. Food Buying 题意 做法 程序 C. Yet Another Walking Robot 题意 做法 程序 D. Fight with Monsters 题意 做法 程序 E1. String Coloring (easy version) 题意 做法 程序 E2. String Coloring (hard version) 题意 做法

[Codeforces Round #617 (Div. 3)] 题解 A,B,C,D,E1,E2,F

[Codeforces Round #617 (Div. 3)] 题解 A,B,C,D,E1,E2,F 1296A - Array with Odd Sum 思路: 如果一开始数组的sum和是奇数,那么直接YES, 否则:如果存在一个奇数和一个偶数,答案为YES,否则为NO 代码: int n; int a[maxn]; int main() { //freopen("D:\\code\\text\\input.txt","r",stdin); //freopen(