题目链接: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. ReactiveCocoa(RAC)

    好处:代码高聚合,方便我们管理: 链式编程: CaculatorMaker.h #import <Foundation/Foundation.h> #define ADD #define ...

  2. Shiro Security

    手动创建shiro Filter的java代码 // Factory<org.apache.shiro.mgt.SecurityManager> factory = new IniSecu ...

  3. js之规范代码写法

    一.避免多次定义var 例如:var a = 0; var b = 1; 尽量定义为:var a = 0,   b =1; 二.尽量在结尾使用分号(semicolon) 否则编辑器会提示:Unterm ...

  4. iOS修改手机定位(非越狱任意位置)

    利用开发者的一些调试功能,我们可以修改非越狱的苹果手机定位,模拟任意位置. 经测试,此方法仅限开发者调试使用,并不能长时间修改手机定位. 1. 首先需要了解一些坐标系的知识 iOS,原生坐标系为 WG ...

  5. 读javascript高级程序设计13-JSON

    JSON是一个轻量级的数据格式,可以简化表示数据结构的工作量.在实际工作中,我们经常用它来传递数据,不过对于其使用的一些细节还是需要注意的.在ECMAScript5中定义了原生的JSON对象,可以用来 ...

  6. 浮动框控制及切换、banner随机数js

    1.浮动置控制及切换 <div class="banner1"></div><div class="bot_banner"> ...

  7. oracle sql

    show user desc 'table' SELECT DISTINCT SELECT * FROM emp WHERE comm is NOT NULL; SELECT * FROM emp W ...

  8. 寻找C语言和.NET之间的桥梁

    一提到C语言,在偶这个始终的C语言菜鸟眼里,是个神奇的语言.经过了近半世纪的历史,多少技术湮灭在信息时代的长河中,C语言却依然在TIBOE排行榜中笑傲群雄. 本文是谈.NET开发者看来,C语言有什么特 ...

  9. linux 下mysql的启动 、调试、排错

    Linux 下 MySQL 启动与关闭 说明 一.启动 1.1  MySQL 进程 可以用ps 命令查看进程: [root@rac2 ~]# ps -ef|grep mysql root     21 ...

  10. 在 Ubuntu 14.04 中配置 PXE 服务器

    PXE(预启动执行环境Preboot Execution Environment)服务器允许用户从网络中启动 Linux 发行版并且可以不需要 Linux ISO 镜像就能同时在数百台 PC 中安装. ...