Table Decorations
你有r个红的,g个绿的和b个蓝的气球。要为宴会布置一张桌子,你恰好需要三个气球。附在桌子上的三个气球不应该有相同的颜色。如果我们知道每种颜色的气球的数量,最多可以装饰多少张桌子?
您的任务是编写一个程序,对于给定的值r、g和b,它将找到表的最大数量t,并且可以按照所需的方式进行装饰。
Input
The single line contains three integers r, g and b (0 ≤ r, g, b ≤ 2·109) — the number of red, green and blue baloons respectively. The numbers are separated by exactly one space.
Output
Print a single integer t — the maximum number of tables that can be decorated in the required manner.
Examples
5 4 3
4
1 1 1
1
2 3 3
2
Note
In the first sample you can decorate the tables with the following balloon sets: "rgg", "gbb", "brr", "rrg", where "r", "g" and "b" represent the red, green and blue balls, respectively.
sol:搞了半天挂了无数次(菜菜菜菜菜菜菜菜菜菜菜菜菜菜菜菜)被日爆了!!!
发现对于a,b,c在大部分情况下都可以凑到总个数不到三个为止(即(a+b+c/3))
注意我说的是大多数,来看一组数据 100000000 1 1
这个最多只有一种,这类情况就是a,b,c中最大的数比另外两个的和的两倍还大,这类的答案就是另外两个的和
Ps:代码短但是好难啊qaq
翻车现场↑
#include <bits/stdc++.h> using namespace std; typedef long long ll; inline ll read() { ll s=0; bool f=0; char ch=' '; while(!isdigit(ch)) { f|=(ch=='-'); ch=getchar(); } while(isdigit(ch)) { s=(s<<3)+(s<<1)+(ch^48); ch=getchar(); } return (f)?(-s):(s); } #define R(x) x=read() inline void write(ll x) { if(x<0) { putchar('-'); x=-x; } if(x<10) { putchar(x+'0'); return; } write(x/10); putchar((x%10)+'0'); return; } #define W(x) write(x),putchar(' ') #define Wl(x) write(x),putchar(' ') ll a,b,c; int main() { ll Max; R(a); R(b); R(c); Max=max(max(a,b),c); if(Max>2*(a+b+c-Max)) Wl(a+b+c-Max); else Wl((a+b+c)/3); return 0; } /* input 5 4 3 output 4 input 1 1 1 output 1 input 2 3 3 output 2 input 100 99 56 output 85 */