Codeforces Round #603 (Div. 2) A. Sweet Problem(数学)
题目链接:https://codeforces.com/contest/1263/problem/A
题意
给出三种糖果的个数,每天吃两种不同的糖果,问最多吃多少天。
题解
如果较少两种糖果的个数和少于最多的一种糖果,那么答案取决于较少的两者。
否则,三者最后会分至最多剩一个糖果,答案即三者的总数对二取下整。
代码
#include <bits/stdc++.h> using namespace std; void solve() { int a[3]; for (auto &i : a) cin >> i; sort(a, a + 3); cout << (a[0] + a[1] < a[2] ? a[0] + a[1] : (a[0] + a[1] + a[2]) / 2) << "\n"; } int main() { int t; cin >> t; while (t--) solve(); }

浙公网安备 33010602011771号