A - Make 10
作者:互联网
https://atcoder.jp/contests/arc126/tasks/arc126_a
题面
We have N2 sticks of length 2 each, N3 sticks of length 3 each, and N
4 sticks of length 4 each. You can do the following operation any number of times.Choose two sticks.
Let x and y be the lengths of these sticks. Bond them to form a stick of length x+y.
Find the maximum number of sticks that can be made whose lengths are exactly 10.
Given T test cases, solve each of them.
input
5
3 4 1
7 0 0
0 0 7
0 0 0
1000000000000000 1000000000000000 1000000000000000
output
2
1
0
0
900000000000000
长度分别为2,3,4的木条,通过粘连操作将其拼成长度为10的木条,在最后输出最大的个数。
先给小木条长度设置优先级,长度为3的应该最先来使用,先用两个3去消耗一个4.
再用两个3消耗两个2.
然后是两个4消耗一个2
现在若长度为4的还有有一个则将其用2消耗掉。
最后加上长为2的个数除以五。
#include <stdio.h>
#include<iostream>
using namespace std;
#define ll long long
void solve()
{
ll a, b, c;
cin>>a>>b>>c;
ll ans = 0;
ll mn = min(b/2, c);//两个3去消耗一个4
ans += mn, b -= mn*2, c -= mn;
ll mn3 = min(b/2, a/2);
ans += mn3, b -= mn3*2, a -= mn3*2;//两个3去消耗两个2
ll mn2 = min(c/2, a);
ans += mn2, c -= mn2*2, a -= mn2;//两个4消耗一个2
if (c>0)
{
if (a >= 3)
{
a -= 3, ans++, c = 0;
}
}
ans += a/5;
cout << ans << '\n';
}
int main()
{
int t = 1;
cin >> t;
while (t--)
solve();
}
标签:10,ll,sticks,Make,mn3,each,ans,mn2 来源: https://blog.csdn.net/weixin_46574282/article/details/120388156