【Codeforces Round 273 (Div 2)C】【贪心 脑洞】 Table Decorations 三种气球装饰桌子 同桌三个气球不完全同色的最多桌子装饰数
2015-12-11 16:58
459 查看
C. Table Decorations
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
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.
Sample test(s)
input
output
input
output
input
output
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.
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1#define rs o<<1|1typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}
template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}
const int N=0,M=0,Z=1e9+7,ms63=1061109567;
LL a[5];
int main()
{
for(int i=1;i<=3;++i)scanf("%lld",&a[i]);
sort(a+1,a+4);
gmin(a[3],(a[1]+a[2])*2);
LL ans=(a[1]+a[2]+a[3])/3;
printf("%lld\n",ans);
return 0;
}
/*
【trick&&吐槽】
1,这种水题可是把zjs整整卡了一个一个小时,哇咔咔。
2,排序出来的结果,我竟然把a[1]当成了最大的,结果wa一发,好蠢!
还好最后还是3分钟就AC了。
【题意】
给你三种颜色的气球,数量分别为a[1],a[2],a[3],数量都在[0,2e9]范围
我们想要用这三种颜色的气球装饰桌子。
每个桌子必须用三个气球来装饰,且三个气球的颜色不能完全相同。
问你,我们最多可以装饰多少个桌子。
【类型】
贪心 脑洞
【分析】
其实我们用自己博大的胸怀(噗)去想一想,就能想到。
不完全相同,这个限制条件,其实是很宽泛的。
如果三种颜色的气球,数量是比较接近的话,答案显然是sum/3
如果不接近,什么情况答案不是sum/3呢?
显然,是有一种气球的数量特别多的时候。
于是,我们排个序,使得a[1]<a[2]<a[3],然后a[3]=min(a[3],a[1]+a[2]<<1)
接着输出sum/3就好啦~
*/
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
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.
Sample test(s)
input
5 4 3
output
4
input
1 1 1
output
1
input
2 3 3
output
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.
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1#define rs o<<1|1typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}
template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}
const int N=0,M=0,Z=1e9+7,ms63=1061109567;
LL a[5];
int main()
{
for(int i=1;i<=3;++i)scanf("%lld",&a[i]);
sort(a+1,a+4);
gmin(a[3],(a[1]+a[2])*2);
LL ans=(a[1]+a[2]+a[3])/3;
printf("%lld\n",ans);
return 0;
}
/*
【trick&&吐槽】
1,这种水题可是把zjs整整卡了一个一个小时,哇咔咔。
2,排序出来的结果,我竟然把a[1]当成了最大的,结果wa一发,好蠢!
还好最后还是3分钟就AC了。
【题意】
给你三种颜色的气球,数量分别为a[1],a[2],a[3],数量都在[0,2e9]范围
我们想要用这三种颜色的气球装饰桌子。
每个桌子必须用三个气球来装饰,且三个气球的颜色不能完全相同。
问你,我们最多可以装饰多少个桌子。
【类型】
贪心 脑洞
【分析】
其实我们用自己博大的胸怀(噗)去想一想,就能想到。
不完全相同,这个限制条件,其实是很宽泛的。
如果三种颜色的气球,数量是比较接近的话,答案显然是sum/3
如果不接近,什么情况答案不是sum/3呢?
显然,是有一种气球的数量特别多的时候。
于是,我们排个序,使得a[1]<a[2]<a[3],然后a[3]=min(a[3],a[1]+a[2]<<1)
接着输出sum/3就好啦~
*/
相关文章推荐
- 1.一些 贪心算法 的简单思维题:
- 贪心算法——字典序最小问题
- 贪心算法——区间调度问题
- Jump Game I,II 贪心
- Wildcard Matching
- 贪心法实现无向图的划分 代码
- 贪心题目循环和控制台折行
- HDOJ 1009
- 【解题报告】【USACO】酸奶工厂
- 【解题报告】【】交谊舞
- POJ 1328
- Best Cow Line
- POJ2377 Bad Cowtractors
- 贪心 hdu 1003
- 最大容器
- 满足和为定值的两个数或多个数
- Codeforces Round #300
- HUD1052 __ P2 1002 __ Tian Ji -- The Horse Racing
- 2015年国家集训队测试 BZOJ3816矩阵变幻
- poj 1328