zoukankan      html  css  js  c++  java
  • 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): 593    Accepted Submission(s): 207


    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
    题意:给三个小球,其中两个不一样颜色的碰一下这两个小球可以变成第三种小球的颜色,问最少需要几步可以让所有的
            球变成同一种颜色
    题解:1、当有两种颜色的小球个数相等时步数就等于这相等个数小球的个数
            2、当其中有一个数与另一个数的差是3的倍数时也可以答案是做差的两个数中较大的那个
    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<algorithm>
    using namespace std;
    bool cmp(int a,int b)
    {
    	return a>b;
    }
    int main()
    {
    	int n,m,j,i,t;
    	int a[10];
    	int x,y;
    	while(scanf("%d%d%d",&a[0],&a[1],&a[2])!=EOF)
    	{
    		sort(a,a+3,cmp);
            if(a[0]==a[1]||a[1]==a[2]||(a[1]-a[2])%3==0)
                printf("%d
    ",a[1]);
            else if((a[0]-a[1])%3==0||(a[0]-a[2])%3==0)
            	printf("%d
    ",a[0]);
            else 
            printf("):
    ");
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    创业第一步:为员工打工
    C#笔记30:Trace、Debug和TraceSource的使用以及日志设计
    C#笔记29:程序集、应用程序配置及App.config和YourSoft.exe.config
    WPF快速指导1:资源
    并行编程之数据并行
    异常处理之ThreadException、unhandledException及多线程异常处理
    Efficient C#:为什么要把泛型作为返回值
    C#笔记31:本地化或多语言支持
    C#数据本地存储方案之SQLite
    C#笔记9:异常
  • 原文地址:https://www.cnblogs.com/tonghao/p/4701379.html
Copyright © 2011-2022 走看看