|
Change the ballTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 482 Accepted Submission(s): 168
Problem Description
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.
Output
For each case, tell Garfield the minimal steps to complete the assignment. If not, output the symbol “):”.
Sample Input
Sample Output
题目大意:两种不同颜色的球可以变成另外一种颜色的球,两种不同颜色的球不能变成其他两种颜色的球 ,将三种不同颜色的球变为一种颜色,最少所需要的次数;
解题思路:首先根据题意,我们可以发现,将两种不同颜色的球变成其他颜色的球,例如(Y,B)->R;
我们可以发现 Y=Y+1;B=B+1;R=R+2;(Y-R)%3==(B-R)%3==0;
也就是说,任意两个球之间只要是3的倍数就一定能变成;将这两种球完全变没有,所得的变化次数一定是MAX(a,b);
最后求最小值就行了;
|
HDU-2277 Change the ball
最新推荐文章于 2017-01-21 13:46:22 发布