「CF478C」Table Decorations
You have r red, g green and b blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn’t have the same color. What maximum number t of tables can be decorated if we know number of balloons of each color?
Your task is to write a program that for given values r, g and b will find the maximum number t of tables, that can be decorated in the required manner.
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.
Print a single integer t — the maximum number of tables that can be decorated in the required manner.
1 |
5 4 3 |
1 |
4 |
1 |
1 1 1 |
1 |
1 |
1 |
2 3 3 |
1 |
2 |
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.
题解
此题乱搞的话很容易FST
赛后对着数据乱搞才过的。。。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
#include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #include<cmath> #include<cstring> #define inf 1000000000 #define ll long long using namespace std; int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int a[5]; int ans; int main() { for(int i=1;i<=3;i++)a[i]=read(); sort(a+1,a+4); int t=min(a[1],(a[3]-a[2])/2); a[1]-=t;a[3]-=t*2;ans+=t; ans+=a[1];a[2]-=a[1];a[3]-=a[1]; t=min(a[2],a[3]-a[2]); a[2]-=t;a[3]-=t*2;ans+=t; if(a[2]>a[3])swap(a[2],a[3]); t=a[2]/3;ans+=t*2; a[2]-=t*3;a[3]-=t*3; if(a[2]*a[3]>=2)ans++; printf("%d\n",ans); return 0; } |
http://blog.csdn.net/caduca/article/details/40183233
当最大的气球数量的一半小于另外两种颜色的数量之和,可以组成全部颜色数量之和/3,否则全部组成为2+1,2为最多数量的颜色
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#include <stdio.h> #include <iostream> #include <cstring> #include <algorithm> #include <cmath> using namespace std; long long i,j,t,n,m,l,r,k,z,y,x; long long g,b,ans; int main() { scanf("%I64d%I64d%I64d",&r,&g,&b); ans=min(min(min((r+g+b)/3,r+g),r+b),b+g); printf("%I64d\n",ans); return 0; } |