题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2277

Change the ball

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

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
题目大意:有三种颜色的球(黄蓝黄),数量各不相同,现在给定每种球的个数,b并且有一种规则(拿起任意两种不同颜色的球他们的颜色会立马变成第三种颜色),问能否经过变换后所有的球都变成同一种颜色、需要的最少次数。
解题思路:能够达到目的的有两种情况:

①有两个球的数量相等(或者是三个都相等)

②有一种球是另一种球数量的三倍(每改变一次,有一个球会增加2个,另两个会各减少1个,中间差了3,也就是说,只有是三的倍数的情况,三个球才能实现完全转化),这种条件就需要分情况了,因为可能是都转化为球最多的那个,也有可能是都转化成球数不是最多的那个(最少次数就为球最多的球数(可以等价为这种球一直在向别的转化))

AC代码:

 #include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int a[];
while (~scanf ("%d %d %d",&a[],&a[],&a[]))
{
sort (a+,a++);
if ( a[] == a[] || (a[] - a[]) % == ) //先看是否能把最少的转化成多的
printf ("%d\n",a[]); //如果可以的话,实际上是 a[2] 一直向 a[1]和 a[3]转化
else if ( a[] == a[] || (a[] - a[]) % == )
printf ("%d\n",a[]); //结合上一种,这一种也可以理解
else if ( a[] == a[] || (a[] - a[]) % == )
printf ("%d\n",a[]); //实际上,这种情况完全可以和上一种合并,但是为了程序的清楚就分开了
//else if ( a[2] == a[3] || (a[3] - a[2]) % 3 == 0 || a[1] == a[3] || (a[3] - a[1]) % 3 == 0 )
// printf ("%d\n",a[3]);
//最后两个 else if 可以合并成这样
else
printf ("):\n");
}
return ;
}
 

HDU 2277 Change the ball的更多相关文章

  1. hdoj 2277 Change the ball【找规律】

    Change the ball Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  2. hdu 1556:Color the ball(第二类树状数组 —— 区间更新,点求和)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  3. hdu 1556:Color the ball(线段树,区间更新,经典题)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  4. Change the ball(找规律)

    Change the ball Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  5. FZU oj 2277 Change 树状数组+dfs序

    Problem 2277 Change Time Limit: 2000 mSec    Memory Limit : 262144 KB  Problem Description There is ...

  6. HDU.1556 Color the ball (线段树 区间更新 单点查询)

    HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...

  7. hdu 1199 Color the Ball

    http://acm.hdu.edu.cn/showproblem.php?pid=1199 Color the Ball Time Limit: 2000/1000 MS (Java/Others) ...

  8. HDU 1556 Color the ball (数状数组)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  9. 线段树(求单结点) hdu 1556 Color the ball

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

随机推荐

  1. microstrip(微带线)、stripline(带状线) 指什么?

    带状线:走在内层(stripline/double stripline),埋在PCB内部的带状走线,如下图所示 蓝色部分是导体,绿色部分是PCB的绝缘电介质,stripline是嵌在两层导体之间的带状 ...

  2. UI设计的分类

    软件UI设计(界面设计包括硬件界面设计和软件界面设计,我们这里探讨的是软件界面设计)包括用户研究.交互设计.与界面设计三部分.   1,用户研究 我们再产品开发的前期,通过调查研究,了解用户的工作性质 ...

  3. hosts代理

    hosts代理文件:C:\Windows\System32\drivers\etc\HOSTS 内容如下: # Copyright (c) -, racaljk. # https://github.c ...

  4. (三)kafka集群扩容后的topic分区迁移

    kafka集群扩容后的topic分区迁移 kafka集群扩容后,新的broker上面不会数据进入这些节点,也就是说,这些节点是空闲的:它只有在创建新的topic时才会参与工作.除非将已有的partit ...

  5. 【java基础】方法2

    让形参可变的方法 jdk1.5之后,java允许定义形参长度可变的参数,允许为方法指定数量不确定的形参. package object; public class VariableParam { // ...

  6. linux下tar.gz、tar、bz2、zip等解压缩、压缩命令小结

    Linux下最常用的打包程序就是tar了,使用tar程序打出来的包我们常称为tar包,tar包文件的命令通常都是以.tar结尾的.生成tar包后,就可以用其它的程序来进 行压缩了,所以首先就来讲讲ta ...

  7. python 正则表达式总结

    一.匹配元字符 使用元字符可以简便操作,写正则表达式时更方便 常用元字符: . 它匹配除了换行字符外的任何字符,在 alternate 模式(re.DOTALL)下它甚至可以匹配换行  ^ 匹配行首. ...

  8. iOS开发 ReactiveCocoa入门教程 第二部分

    ReactiveCocoa 是一个框架,它允许你在你的iOS程序中使用函数响应式(FRP)技术.加上第一部分的讲解,你将会学会如何使用信号量(对事件发出数据流)如何替代标准的动作和事件处理逻辑.你也会 ...

  9. CSS权重及样式优先级问题

    CSS权重值计算 一条样式规则的整体权重值包含四个独立的部分:[A, B, C, D]; (1) A 表示内联样式(写在标签的style属性中),只有 1 或者 0 两个值:对于内联样式,由于没有选择 ...

  10. PR和VV的分类与区别

    Adobe Premiere是一款常用的视频编辑软件,由Adobe公司推出.现在常用的有CS4.CS5.CS6.CC.CC 2014及CC 2015版本.是一款编辑画面质量比较好的软件,有较好的兼容性 ...