CodeForces 478C (贪心)
来源:互联网 发布:装甲少女 知乎 编辑:程序博客网 时间:2024/04/24 02:42
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.
5 4 3
4
1 1 1
1
2 3 3
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.
题意 :题意就是 一个桌子可以布置三个气球,这三个气球不能是一样的,现在给你三种气球的总数,问你有多少种情况 。
思路:最初看到这道题 ,就是一组数同时对他们-0,-1,-2,问你减到0,0,0有多少次,这样一看 ,是不是像是 搜索,但是数据范围巨大,肯定不是啦。。,所以最终解法是这样,对这三个数进行排序,前两个较小的数如果小于较大数的二倍的话,那么答案就是前两个数相加,为什么是这样,我们都知道 最好的方法就是在最大中取两个,最小的当中取一个,那么就是这样写的啦,然后 大于他的二倍的话到最后就不能这样分了,那么他最后肯定会剩下,那就直接除3,为什么,因为最后剩下的数肯定不会超过3,因为如果超过三的情况下那他就能在分出一个了,比如1,1,1;1,2,1这些都能再分出去,所以他剩下的总数不可能超过三 ,那么我们直接除3的话得到的就是最后答案
上代码:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int main(){long long a[3];scanf("%lld%lld%lld",&a[0],&a[1],&a[2]);sort(a,a+3);if((a[0]+a[1])*2<=a[2]){printf("%d\n",a[0]+a[1]);}else{printf("%d\n",(a[0]+a[1]+a[2])/3);}}
- CodeForces 478C (贪心)
- CodeForces 508C (贪心)
- Codeforces 805C (贪心)
- codeforces-478C-Table Decorations【贪心】
- Codeforces 478C Table Decorations【贪心】【思维】
- Codeforces 478C Table Decorations【贪心】
- Codeforces 478C Table Decorations 贪心(思维!!!)
- Codeforces 394C Dominoes(贪心)
- Codeforces 401C Team(贪心+暴力)
- CodeForces 416C Booking System(贪心)
- CodeForces 460C--- Present(二分+贪心)
- CodeForces 219C Color Stripe (贪心)
- codeforces 219C Color Stripe(贪心)
- CodeForces 545C Woodcutters (贪心)
- codeforces 600C. Make Palindrome(贪心)
- codeforces 416C Booking System (贪心)
- CodeForces 626 C. Block Towers(贪心)
- CodeForces 615 C. Running Track(贪心)
- JZOJ 5186. 【NOIP2017提高组模拟6.30】tty's home
- 【Java线程】锁机制:synchronized、Lock、Condition
- 大数据与时间
- Spark核心编程:高级编程之二次排序
- 如何完整的安装Cygwin
- CodeForces 478C (贪心)
- Android开发——简述RxJava框架的实现原理
- Linux下的mysleep
- Python中的装饰器
- 《Scrum实战》学习规划
- js面向对象组件开发---弹窗
- 在Android-x86 M上運行xposed程序
- Java中IO流,输入输出流概述与总结 IO流关系图解
- pwnable.kr之fd