Codeforces Round #603 (Div. 2)A. Sweet Problem(水题)

题目链接:

https://codeforces.com/problemset/problem/1263/A

题面:

‘’

题意:

给定三种糖的数量 r , g , b r,g,b ,现在一天必须吃两个不一样的糖,问最多能吃多少天。

思路:

首先确定三种糖果的数量大小, s o r t sort 排序后,很好理解 a [ 0 ] + a [ 1 ] a [ 2 ] a[0]+a[1] \leq a[2] 则只能吃 a [ 0 ] + a [ 1 ] a[0]+a[1] 天,如果 a [ 2 ] a [ 0 ] ] + a [ 1 ] a[2] \leq a[0]]+a[1] ,则有 a [ 0 ] a [ 1 ] a [ 2 ] a [ 0 ] + a [ 1 ] + a [ 2 ] 2 a[0]\leq a[1] \leq a[2]\leq \frac{a[0]+a[1]+a[2]}{2} ,答案就是 a [ 0 ] + a [ 1 ] + a [ 2 ] 2 \frac{a[0]+a[1]+a[2]}{2}

参考代码:

/* CF was purple years ago!
 * Thanks cf-tool!
 * Author: nuoyanli
 * Time: 2019-12-08 12:59:09
 **/

//#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#define inf 0x3f3f3f3f
#define lson l, mid, root << 1
#define rson mid + 1, r, root << 1 | 1
#define min(a, b) a > b ? b : a
#define max(a, b) a < b ? b : a
#define ll long long
using namespace std;
const int N = 2e5 + 10;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin >> t;
	while (t--) {
		int a[3],sum=0;
		for(int i=0; i<3; i++)cin>>a[i],sum+=a[i];
		sort(a,a+3);
		if(a[0]+a[1]>=a[2]){
			cout<<(int)sum/2<<endl;
		}else{
			cout<<sum-a[2]<<endl;
		}
	}
	return 0;
}
发布了293 篇原创文章 · 获赞 212 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/nuoyanli/article/details/103454067