链接:
https://codeforces.com/contest/1263/problem/A
题意:
You have three piles of candies: red, green and blue candies:
the first pile contains only red candies and there are r candies in it,
the second pile contains only green candies and there are g candies in it,
the third pile contains only blue candies and there are b candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can‘t eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
思路:
排序得到r >= g >= b
考虑r >= g+b,答案是g+b
否则让r,g,b三个相等
首先让r=g,r减去r-g, b减去r-g(保证可行,r < g+b => b > r-g)
再让r = g = b,r和g同时减去g-(b-(r-g)),三者最后为b+g-r
考虑三个相等,即可。
代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[3];
int t;
cin >> t;
while(t--)
{
for (int i = 0;i < 3;++i)
cin >> a[i];
sort(a, a+3);
if (a[2] >= a[1]+a[0])
cout << a[1]+a[0] << endl;
else
{
int ans = 0;
ans += (a[2]-a[1])+(a[2]-a[0]);
int t = a[0]-a[2]+a[1];
ans += (3*t)/2;
cout << ans << endl;
}
}
return 0;
}
原文地址:https://www.cnblogs.com/YDDDD/p/12053774.html