Codeforces Round #273 (Div. 2)(C)贪心,思维
2016-03-10 13:59
281 查看
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.
Examples
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.
题意:你有,红绿蓝,三种颜色的气球,分别有R,G,B个,现在有桌子需要你装饰,装饰的规则是每个桌子装饰三个气球,三个气球的颜色不能完全相同,问最多可以装饰多少桌子?
题解:如果R,G,B大小相近,那么就直接输出平均数就可以了,那如果最大的那个数字很大呢?我们最多可以利用的个数就是MAX=min(MAX,(其他2个的颜色的和)*2),他最多可以与另2种颜色组合他们的和的2倍,剩余更多的无法利用,然后输出平均值就可以了
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<bitset>
#include<utility>
#include<functional>
#include<iomanip>
#include<sstream>
#include<ctime>
#include<cassert>
using namespace std;
#define N int(1e5)
#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
typedef long long LL;
#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)
#define lld "%I64d"
#else
#define lld "%lld"
#endif
#ifdef CDZSC
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
priority_queue<LL>q;
int main()
{
#ifdef CDZSC
freopen("i.txt", "r", stdin);
//freopen("o.txt","w",stdout);
int _time_jc = clock();
#endif
LL a[10];
while (~scanf("%lld",&a[0]))
{
LL ans = 0;
for (int i = 1; i <= 2; i++)
{
scanf("%lld", &a[i]);
}
sort(a, a + 3);
a[2] = min(a[2], (a[1] + a[0])<<1);
printf("%lld\n", (a[0]+a[2]+a[1])/3);
}
#ifdef CDZSC
debug("time: %d\n", int(clock() - _time_jc));
#endif
return 0;
}
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.
Examples
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.
题意:你有,红绿蓝,三种颜色的气球,分别有R,G,B个,现在有桌子需要你装饰,装饰的规则是每个桌子装饰三个气球,三个气球的颜色不能完全相同,问最多可以装饰多少桌子?
题解:如果R,G,B大小相近,那么就直接输出平均数就可以了,那如果最大的那个数字很大呢?我们最多可以利用的个数就是MAX=min(MAX,(其他2个的颜色的和)*2),他最多可以与另2种颜色组合他们的和的2倍,剩余更多的无法利用,然后输出平均值就可以了
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<bitset>
#include<utility>
#include<functional>
#include<iomanip>
#include<sstream>
#include<ctime>
#include<cassert>
using namespace std;
#define N int(1e5)
#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
typedef long long LL;
#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)
#define lld "%I64d"
#else
#define lld "%lld"
#endif
#ifdef CDZSC
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
priority_queue<LL>q;
int main()
{
#ifdef CDZSC
freopen("i.txt", "r", stdin);
//freopen("o.txt","w",stdout);
int _time_jc = clock();
#endif
LL a[10];
while (~scanf("%lld",&a[0]))
{
LL ans = 0;
for (int i = 1; i <= 2; i++)
{
scanf("%lld", &a[i]);
}
sort(a, a + 3);
a[2] = min(a[2], (a[1] + a[0])<<1);
printf("%lld\n", (a[0]+a[2]+a[1])/3);
}
#ifdef CDZSC
debug("time: %d\n", int(clock() - _time_jc));
#endif
return 0;
}
相关文章推荐
- http客户端通信 (java原生)
- 添加远程库
- opencv CvMat转Mat
- hihoCoder 1032 最长回文子串(Manacher算法)
- 曾经困扰过我的sql
- angularjs flask跨域问题 XMLHttpRequest cannot load. No 'Access-Control-Allow-Origin'
- 移植OpenWrt到CuHead Pro WiFi
- 正则表达式 - 语法
- 【ActionBar的使用】
- 安卓之检测网络
- Android中的颜色设置
- easyui tree的简单使用
- [转]Node-Webkit配合HTML5实现拍照功能
- 正则表达式 - 简介
- Java基础知识之集合框架(一)
- CSS3中:nth-child和:nth-of-type的区别深入理解
- android如何实现国际化
- 发动机外特性曲线(工况图)疑惑
- 【iCore3 双核心板_FPGA】例程九:状态机实验——状态机使用
- JSP弹框界面