Educational Codeforces Round 73 (Rated for Div. 2) C. Perfect Team

链接:

https://codeforces.com/contest/1221/problem/C

题意:

You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.

So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.

You are a coach at a very large university and you know that c of your students are coders, m are mathematicians and x have no specialization.

What is the maximum number of full perfect teams you can distribute them into?

Note that some students can be left without a team and each student can be a part of no more than one team.

You are also asked to answer q independent queries.

思路:

将c, m变成min(c, m), 多的加到x中, 先得到min(c, x),如果x大, 那么答案不可能用x剩下的组合.
如果c大, 因为剩下的c=m所以可以继续使用.
或者不改变直接二分判断答案也可以

代码:

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t, a, b, c;
    cin >> t;
    while (t--)
    {
        cin >> a >> b >> c;
        if (a < b)
            swap(a, b);
        c += (a-b);
        a = b;
        int sum = min(a, c);
        a -= sum, b -= sum, c -= sum;
        cout << sum+(a+b)/3 << endl;
    }

    return 0;
}

猜你喜欢

转载自www.cnblogs.com/YDDDD/p/11624811.html