cf1561B. Charmed by the Game

Posted Jozky86

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cf1561B. Charmed by the Game相关的知识,希望对你有一定的参考价值。

cf1561B. Charmed by the Game

题意:

两人轮流发球,有两种得分的情况,一个是自己发球的回合得分,叫做"holds",另一种是在对方发球的回合得分,叫做"breaks",现在给出比赛结束后两个人的得分,问你两个人总的"breaks"的次数有多少种情况。不知道谁先发球,也不知道谁哪个回合取胜,只知道最后的得分

题解:

我们知道两人得分是x,y,总比赛数量就是x+y,先手发球次数为p= ⌈ a + b 2 ⌉ \\lceil \\frac{a+b}{2} \\rceil 2a+b,后手为q= ⌊ a + b 2 ⌋ \\lfloor \\frac{a+b}{2} \\rfloor 2a+b
现在也不知道谁先发球,我们可以设Alice先发球,设x为Alice输掉场次为a(0<=a<=p),设Borys输掉场次为b(0<=b<=q)
如果Alice先发球,枚举Alice输的个数a,从0到p,然后有x=(p-a)+y,y=x-(p-a),只要y满足(0<=y<=q),这就是合法的情况,k就是x+y
Borys发球时同理

代码:


// Problem: B. Charmed by the Game
// Contest: Codeforces - Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine))
// URL: https://codeforces.com/contest/1561/problem/B
// Memory Limit: 512 MB
// Time Limit: 2000 ms
// Data:2021-08-24 23:07:04
// By Jozky

#include <bits/stdc++.h>
#include <unordered_map>
#define debug(a, b) printf("%s = %d\\n", a, b);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
clock_t startTime, endTime;
//Fe~Jozky
const ll INF_ll= 1e18;
const int INF_int= 0x3f3f3f3f;
void read(){};
template <typename _Tp, typename... _Tps> void read(_Tp& x, _Tps&... Ar)
{
    x= 0;
    char c= getchar();
    bool flag= 0;
    while (c < '0' || c > '9')
        flag|= (c == '-'), c= getchar();
    while (c >= '0' && c <= '9')
        x= (x << 3) + (x << 1) + (c ^ 48), c= getchar();
    if (flag)
        x= -x;
    read(Ar...);
}
template <typename T> inline void write(T x)
{
    if (x < 0) {
        x= ~(x - 1);
        putchar('-');
    }
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}
void rd_test()
{
#ifdef LOCAL
    startTime= clock();
    freopen("in.txt", "r", stdin);
#endif
}
void Time_test()
{
#ifdef LOCAL
    endTime= clock();
    printf("\\nRun Time:%lfs\\n", (double)(endTime - startTime) / CLOCKS_PER_SEC);
#endif
}
int main()
{
    //rd_test();
    int t;
    read(t);
    while (t--) {
        int x, y;
        read(x, y);
        if ((x + y) % 2) {
            int ans= 2 * (min(x, y) + 1);
            printf("%d\\n", ans);
            int tot= (x + y) / 2 - min(x, y);
            for (int i= 1; i <= ans; i++) {
                printf("%d ", tot);
                tot++;
            }
        }
        else if ((x + y) % 2 == 0) {
            int ans= (min(x, y) + 1);
            printf("%d\\n", ans);
            int tot= (x + y) / 2 - min(x, y);
            for (int i= 1; i <= ans; i++) {
                int ans= (x + y) / 2 - min(x, y) + 2 * (i - 1);
                printf("%d ", ans);
            }
        }
        printf("\\n");
    }
    return 0;
    //Time_test();
}


以上是关于cf1561B. Charmed by the Game的主要内容,如果未能解决你的问题,请参考以下文章

cf1561C. Deep Down Below

HDU - 1561 The more,The Better

hdu 1561 The more, The Better(树形dp)

[USACO08FEB]Making the Grade G 和 CF714E

[USACO08FEB]Making the Grade G 和 CF714E

hdu1561The more, The Better(树形背包)