6Luffy6

导航

CF1221C Perfect Team

传送锚点

问题 - 1221C - Codeforces --- Problem - 1221C - Codeforces

Perfect Team - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

Perfect Team - CodeForces 1221C - Virtual Judge (vjudge.net)

Perfect Team

题面翻译

题目描述

您可能已经知道标准的ICPC团队正好由三名成员组成。然而,完美的团队有更多的限制。学生可以有一些专业:编码或数学家。她/他可以没有专业化,但不能同时拥有两者。

因此,如果团队至少包括一名编码员,至少有一名数学家,并且由三名成员组成,那么团队就被认为是完美的。

你是一所非常大的大学的教练,你知道你的学生的\(c\) 是编码员,\(m\) 是数学家,\(x\) 没有专业。

您可以分配给他们的最佳完整团队的最大数量是多少?

请注意,有些学生可能没有团队,每个学生都可以成为一个团队的一员。

您还被要求回答\(q\) 个独立查询。

输入格式

第一行包含单个整数 \(q\)($ 1 \leq q \leq 10 ^4$) : 查询数量。

每个一个\(q\) 包含三个整数\(c\) , \(m\)\(x\) ( 0 \(\leq c,m,x \leq 10^8\)) : 分别表示编码员,数学家和没有任何专业的学生的数量。

请注意,没有学生同时是编码员和数学家。

输出格式

每行输出 \(q\) 个整数,它们的第\(i\) 个应该是\(i\) 查询的答案,按照它们在输入中给出的顺序。答案是您可以将学生分配到的完整完美团队的最大数量。

题目描述

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.

输入格式

The first line contains a single integer $ q $ ( $ 1 \le q \le 10^4 $ ) — the number of queries.

Each of the next $ q $ lines contains three integers $ c $ , $ m $ and $ x $ ( $ 0 \le c, m, x \le 10^8 $ ) — the number of coders, mathematicians and students without any specialization in the university, respectively.

Note that the no student is both coder and mathematician at the same time.

输出格式

Print $ q $ integers — the $ i $ -th of them should be the answer to the $ i $ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.

样例 #1

样例输入 #1

6
1 1 1
3 6 0
0 0 0
0 1 1
10 1 10
4 4 1

样例输出 #1

1
3
0
0
1
3

提示

In the first example here are how teams are formed:

  1. the only team of 1 coder, 1 mathematician and 1 without specialization;
  2. all three teams consist of 1 coder and 2 mathematicians;
  3. no teams can be formed;
  4. no teams can be formed;
  5. one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team;
  6. one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int solve(){
    int c, m, x;
    cin >> c >> m >> x;
    int ans = 0;//完美队数 
    if(m == 0 || c == 0){// 如果一个数学家或程序猿 都没有 直接返回0 
        return 0;
    }
    int p = min(c, min(m, x)); //找到c、m、x中的最小值 队数为p 
    c -= p; m -= p; x -= p;
    
    ans += p;
    int l = -1, r = (c + m) / 3 + 1;//对最大完美队数 开区间二分 
    auto check = [&](int x){
    	//假如现在剩c = 3, m = 3,此时x = 2
		 //C: 3 - 2 >= 0  m : 3 - 2 >= 0 
		 //c + m >= 3 * x 等价于  c - x + m - x >= x  
        if(c - x >= 0 && m - x >= 0 && (c + m >= 3 * x)){ 
//c、m中都要抽离x人,组成x个队,然后每个队缺少1个人,再从c、m剩下的人选择 
            return true;
        }
        return false;
    };
    while(l + 1 < r){
        int mid = (l + r) / 2;
        if(check(mid)){
            l = mid;
        }else{
            r = mid;
        }
    }
    ans += l;
    return ans; 
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while(t--){
        int ans = solve();
        cout << ans << endl;
    }
    return 0;
}

posted on 2024-07-30 00:34  不AC不睡觉  阅读(6)  评论(0编辑  收藏  举报