zoukankan      html  css  js  c++  java
  • Change the ball--hdu2277

    Change the ball

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

    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种颜色小球变成一种颜色的最少步数!
     
    分析一下,最直接的就是有两种小球的个数相等,不相等的要想办法转化!每次转化一次两种小球个数各减一,另一种会加二,这中间就差了3!也就是说如果两种小球的个数是3的倍数,就可以转化为两种小球相等,就可以转化为一种颜色!从而有下面代码!
     
     
     1 #include <stdio.h>
     2 #include<algorithm>
     3 using namespace std;
     4 int main()
     5 {
     6     int a[4];
     7     while(scanf("%d%d%d",&a[1],&a[2],&a[3])!=EOF)
     8     {
     9         sort(a+1,a+4);//保证从小到大排序!
    10         if(a[2]==a[1]||(a[2]-a[1])%3==0)
    11         printf("%d
    ",a[2]);
    12         else if(a[2]==a[3]||a[1]==a[3]||(a[3]-a[2])%3==0||(a[3]-a[1])%3==0)
    13         printf("%d
    ",a[3]);
    14         else
    15         printf("):
    ");
    16     }
    17     return 0;
    18 }
     
     
     

     

  • 相关阅读:
    Codeforces Round #595 (Div. 3) C题题解
    Educational Codeforces Round 83 (Rated for Div. 2)
    【算法竞赛进阶指南】Supermarket 贪心+并查集
    【算法竞赛进阶指南】字典树 The XOR Longest Path
    【算法竞赛进阶指南】字典树 The XOR Largest Pair
    【算法进阶指南】双端队列 DP+思维
    【算法进阶指南】蚯蚓 队列
    【2019 杭电多校第一场】Path 最短路+最小割
    【2017 ICPC 沈阳】G.Infinite Fraction Path 暴力优化
    【2017 CCPC 秦皇岛】A.Balloon Robot 思维
  • 原文地址:https://www.cnblogs.com/Eric-keke/p/4680455.html
Copyright © 2011-2022 走看看