CF1792B

· · 题解

这道题非常简单,首先我们考虑顺序。肯定先讲两个人都喜欢的笑话,然后讲一个人喜欢的,轮流讲,先将其中一个人喜欢的,再讲另一个人喜欢的,一样讲一个,就会保持开心值不变。最后讲完剩下的单个人喜欢的笑话,最后将都不喜欢的。要时刻判断有没有人离场。

首先特判,如果没有两个人都喜欢的笑话,剩下的笑话讲哪个都会有人离场,输出 1

然后讲两个人都喜欢的笑话,两个人的开心值为笑话的数量 a_1

然后判断 a_2 a_3 哪个小,也就是可以轮流讲的数量,开心值不变。

然后判断剩下的笑话能不能讲完即可。

代码如下:

# include <bits/stdc++.h>

# define gt getchar

# define pc putchar

# define rep(i, a, b) for (register int i = (a); i <= (b); ++ i)

# define per(i, a, b) for (register int i = (a); i >= (b); -- i)

# define File(x, y) freopen (x, "r", stdin), freopen (y, "w", stdout)

# define int LL

using namespace std;

typedef long long LL;

typedef unsigned long long ULL;

const int N = 10000005;

const int M = 5005;

const int INF = 2147483647;

namespace IO {

    inline void read (int &x) {

        int ret = 0, sgn = 0, ch = gt ();

        while (! isdigit (ch)) sgn |= ch == '-', ch = gt ();

        while (isdigit (ch)) ret = (ret << 3) + (ret << 1) + (ch ^ 48), ch = gt ();

        x = (sgn ? -ret : ret);

    }

    inline void print (int x) {

        if (x < 0) pc ('-'), x = -x;

        int ret = 0, ch[40];

        do { ch[++ ret] = x % 10 + 48, x /= 10; } while (x);

        while (ret) pc (ch[ret]), -- ret;

    }

    inline void printsp (int x) {

        print (x);

        pc (' ');

    }

    inline void println (int x) {

        print (x);

        pc ('\n');

    }

    inline void puts (string s) {

        int len = s.length ();

        rep (i, 0, len - 1) pc (s[i]);

        pc ('\n');

    }

} ;

using namespace IO;

inline void solve () ;

signed main () {

    int T = 1;

    read (T);

    while (T --) {

        solve ();

    }

    return 0;

}

int a, b, c, d;

inline void solve () {

    read (a), read (b), read (c), read (d);

    if (a == 0) { puts ("1"); return ; }

    int ans = a;

    ans += min (b, c) * 2;

    if (max (b, c) - min (b, c) > a) { println (ans + a + 1); return ; }

    ans -= min (b, c) * 2, ans += b, ans += c;

    int ed = (a - max (b, c) + min (b, c) == d ? 0 : 1);

    if (a - max (b, c) + min (b, c) > d) println (ans + d);

    else println (ans + (a - max (b, c) + min (b, c)) + ed);

    return ;

}