hdoj 2277 Change the ball【规律题】

Change the ball

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 584    Accepted Submission(s): 202


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
  
  
1 2 3 1 2 2
 

Sample Output
  
  
): 2
 
题目描述:
加菲尔德有三堆的球,每一堆都有独特的颜色:黄色,蓝色和红色。现在我们也知道加菲尔德有黄色的球,蓝色的球,和红色的球。  
但加菲尔德只是想换一种颜色的球。当他把两个不同颜色的球球一起,并改变其颜色自动到其余的颜色。 例如,当加菲尔德把一个红色和黄色的一起, 两球 立即拥有蓝色 ,其他情况相同。但当球有相同颜色的时候,规则就不工作了。

加菲尔德是无法估计的最小步骤,以达到目标。你能告诉他吗?

所以,需要找规律,任意两球个数相等 即为余下的步骤数;若两球差  刚好是3的倍数,那么,刚好能转化完,步骤数为二者中较大的那个数,当然还要用到快排~

代码:

#include<stdio.h>
#include<algorithm>
using namespace std;
int main()  
{  
    int a[3];  
    while(scanf("%d%d%d",&a[0],&a[1],&a[2])!=EOF)  
    {  
        sort(a,a+3);  
        if(a[0]==a[1]||(a[1]-a[0])%3==0)  
        {  
            printf("%d\n",a[1]);  
        }  
        else if(a[1]==a[2]||(a[2]-a[0])%3==0||(a[2]-a[1])%3==0)  
        {  
            printf("%d\n",a[2]);  
        }  
        else  
            printf("):\n");    
    }  
    return 0;  
} 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值