题目链接: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. C library function - rewind()

    Description The C library function void rewind(FILE *stream) sets the file position to the beginning ...

  2. WCF 4.0 进阶系列 -- 随笔汇总

    WCF4.0 进阶系列–前言 WCF4.0 进阶系列--第一章 WCF简介 WCF4.0进阶系列--第二章 寄宿WCF服务 WCF4.0进阶系列--第三章 构建健壮的程序和服务 WCF4.0进阶系列- ...

  3. CSS-浮动篇float

    Float是一个强大的属性,但是它也会困扰我们如果我们不知道它的工作原理的话.这篇文章主要介绍float的原理和基本用法. 我们可以看到float在印刷世界的应用-杂志.很多杂志文章都是左边一个图片, ...

  4. linux应用程序开发-文件编程-库函数

    ---恢复内容开始--- c库函数文件操作独立于具体的系统平台,可移植性较好. 库函数-创建和打开 FILE*fopen(const char*filename,const char*mode) mo ...

  5. 12款最佳Linux命令行终端工具, 20款优秀的 Linux 终端仿真器

    12款最佳Linux命令行终端工具     如果你跟我一样,整天要花大量的时间使用Linux命令行,而且正在寻找一些可替代系统自带的老旧且乏味的终端软件,那你真是找对了文章.我这里搜集了一些非常有趣的 ...

  6. c++ *.h和*.cpp在编译中的作用

    首先,我们可以将所有东西都放在一个.cpp文件内.然后编译器就将这个.cpp编译成.obj,obj是什么东西?就是编译单元了. 一个程序,可以由一个编译单元组成,也可以有多个编译单元组成. 如果你不想 ...

  7. Spring Boot Admin 的使用 2

    http://blog.csdn.net/kinginblue/article/details/52132113 ******************************************* ...

  8. android通知栏Notification点击,取消,清除响应事件

    主要是检测android通知栏的三种状态的响应事件 这次在实现推送需求的时候,要用到android通知栏Notification点击后进入消息页面,因为要实现一个保存推送用户名字的功能,我在点击后处理 ...

  9. ring0

    Intel的x86处理器是通过Ring级别来进行访问控制的,级别共分4层,RING0,RING1,RING2,RING3.Windows只使用其中的两个级别RING0和RING3. RING0层拥有最 ...

  10. Yii2框架安装(windows)

    -->安装PHP环境Wamp集成环境,XAMMP等.-->安装Composerhttp://pan.baidu.com/s/1i3fejjvPS:安装过程中的有一个手动操作项选择php.e ...