[ABC422C]AtCoder AAC Contest题解
Time Limit: 2 sec / Memory Limit: 1024 MiB
Score : 300 points
Problem Statement
Takahashi has some letters. Each letter he has is A, B, or C. Initially, he has nA letters A, nB letters B, and nC letters C.
He can hold one contest by using one letter A, one letter C, and additionally any one letter, for a total of three letters. Specifically, he can hold AAC by using two letters A and one letter C, ABC by using one letter each of A, B, and C, and ACC by using one letter A and two letters C.
He wants to hold as many contests as possible using the letters he currently has. Find the maximum number of contests he can hold.
T test cases are given, so report the answer for each of them.
讯飞听见 翻译
###问题陈述
高桥有一些信。他的每个字母都是'a'、'B'或'C'。
最初,他有 nA 个字母'A'、 nB 个字母'B'和 nC 个字母“C”。他可以通过使用一个字母“A”、一个字母“C”以及附加的任何一个字母来举行一次比赛,总共三个字母。
具体地,他可以通过使用两个字母“A”和一个字母“C”来保持“AAC”,通过使用“A”、“B”和“C”中的每个字母来保持“ABC”,和通过使用一个字母“A”和两个字母“C”来表示“ACC”。他想用他现有的字母举办尽可能多的比赛。找出他能举办比赛的最大数量。
T 测试用例已给出,因此请报告每个测试用例的答案。
Constraints
- 1≤T≤2×105
- For each test case,
- 0≤nA≤109
- 0≤nB≤109
- 0≤nC≤109
- All input values are integers.
讯飞听见 翻译
###约束
- 1≤T≤2×105
-对于每个测试用例,
-
0≤nA≤109
-
0≤nB≤109
-
0≤nC≤109
-所有输入值均为整数。
Input
The input is given from Standard Input in the following format:
T testcase1 testcase2 ⋮ testcaseT
testcasei (1≤i≤T) represents the i-th test case and is given in the following format:
nA nB nC
讯飞听见 翻译
###输入
输入来自标准输入,格式如下:
T
testcase1
testcase2
⋮
testcaseT
testcasei (1≤i≤T) 代表第 i 个测试用例,格式如下:
nA nB nC
Output
Output over T lines. On the i-th line (1≤i≤T), output the answer to the i-th test case.
讯飞听见 翻译
###输出
通过 T 行输出。在第 i 行 (1≤i≤T) 上,输出第 i 个测试用例的答案。
Sample Input 1
Copy
5 3 1 2 100 0 0 1000000 1000000 1000000 31 41 59 1000000000 10000 1
Sample Output 1
Copy
2 0 1000000 31 1
思路
注意到每个都要用到a,c所以优先abc然后若a>=c*2,c>=a*2显然为少数的,否则除以三取下整。
代码见下
#include<bits/stdc++.h>
using namespace std;
long long t,a,b,c;
int main(){
cin>>t;
while(t--){
cin>>a>>b>>c;
if(a<=b||c<=b){
cout<<min(a,min(b,c))<<endl;
}
else{
a-=b;
c-=b;
if(a>=2*c){
cout<<c+b<<endl;
}
else if(c>=2*a){
cout<<a+b<<endl;
}
else{
cout<<b+((long long)(a+c)/3)<<endl;
}
}
}
return 0;
}

浙公网安备 33010602011771号