hd2277
2015-07-25 19:23
281 查看
Change the ball
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)[align=left]Problem Description[/align]
Garfield has three piles of balls, each pile has unique color of following: yellow, blue, and red. Now we also know Garfield has Y yellow balls, B blue balls, and R red balls. But Garfield just wants to change all the balls to one
color. When he puts two balls of different color togather, the balls then change their colors automatically into the rest color. For instance, when Garfield puts a red one and a yellow one togather, the two balls immediately owns blue color, the same to other
situations. But the rule doesn’t work when the two balls have the same color.
Garfield is not able to estimate the minimal steps to achieve the aim. Can you tell him?
Input
For each line, there are three intergers Y, B, R(1<=Y,B,R<=1000),indicate the number refered above.
[align=left]Output[/align]
For each case, tell Garfield the minimal steps to complete the assignment. If not, output the symbol “):”.
[align=left]Sample Input[/align]
1 2 3 1 2 2
[align=left]Sample Output[/align]
): 2 恩,题目大意就是说黄色,蓝色,红色三种颜色的气球分别为y,b,r个,然后任意两个不同颜色的球放一起都会变成剩下的那一种颜色,现在呢出题人十分无聊的想要把所有的气球都变为一种颜色,问能否实现,若不能输出哭脸,若能输出最小次数。 恩,规律题,不会做,没找对规律。经过大神学长讲了之后才懂,若三个数有一个比另外一个大3的倍数就一定能实现。然后我是每次都把气球往最少的那种颜色去,然后就没有然后了。。。。。#include<stdio.h> #include<algorithm> int a[4]; int mm() { if((a[1]-a[0])%3==0||(a[2]-a[1])%3==0||(a[2]-a[0])%3==0) return 1; return 0; } using namespace std; int main() { int i,c; while(~scanf("%d%d%d",&a[0],&a[1],&a[2])) { c=0; sort(a,a+3); if(!mm())printf("):\n"); else { while(a[0]!=a[1]&&a[1]!=a[2]&&a[0]!=a[2]) { a[0]+=2; a[1]--; a[2]--; c++; sort(a,a+3); } if(a[0]==a[1])c+=a[0]; else if(a[1]==a[2])c+=a[1]; printf("%d\n",c); } } return 0; }
相关文章推荐
- UVA - 10976 Fractions Again?!
- js输入当前页面的HTML代码
- 【LeetCode】239. Sliding Window Maximum
- 数据类型运算符和变量
- 2015.07.25总结
- OC_路径寻找
- 股票学习(技术指标--个股贡献度)
- 图的深度遍历
- springMVC的前端控制器的配置
- Combination Sum III
- Android 限制只输入某些值包括数字、字母等
- 在PL/SQL中使用日期类型
- 车道检测数据集
- 特拉帕尼中文离线地图App上线
- OC_继承,便利构造器,初始化方法
- Android 解析AsyncTask(一)
- c# BackGroundWorker 多线程操作的小例子
- UVa 10570 - Meeting with Aliens(构造法)
- vps mark
- st3插件之emmet的强大