Change the ball

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

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
题解:如果可以变为一种颜色,中间必有两个数相等,假设气球数目刚开始为x,y,z;当碰撞n次时则有,x-n,y+2n,z-n;
若想成功,则有x-n=y+2n或y+2n=z-n;则有x-y=3n或x-z=3n;此时需要再碰撞x-n次则成功,由于刚开始已经碰了n次,则总次数为x-n+n=x也就是较大的数;
则有任意两个数相减出现3的倍数时碰撞成功,否则失败;另外还要找到最小次数,所以sort排序;
代码:
 #include<stdio.h>
#include<algorithm>
using namespace std;
#define MAX(x,y) x>y?x:y
#define MIN(x,y) x<y?x:y
int judge(int x,int y){
int a,b;
a=MAX(x,y);
b=MIN(x,y);
if((a-b)%==)return a;
else return ;
}
int main(){
int Y,B,R,temp[],flot;
while(~scanf("%d%d%d",&Y,&B,&R)){flot=;
temp[]=judge(Y,B),temp[]=judge(Y,R),temp[]=judge(B,R);
sort(temp,temp+);
for(int i=;i<;i++){
if(temp[i]){flot=;
printf("%d\n",temp[i]);break;
}
}
if(flot)printf("):\n");
}
return ;
}

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 1792 A New Change Problem (GCD+打表找规律)

    Problem Description Now given two kinds of coins A and B,which satisfy that GCD(A,B)=1.Here you can ...

  3. codeforces D. Queue 找规律+递推

    题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...

  4. HDU 4861 Couple doubi (数论 or 打表找规律)

    Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...

  5. HDU 4861 Couple doubi(找规律|费马定理)

    Couple doubi Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  6. 计蒜客 39279.Swap-打表找规律 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest L.) 2019ICPC西安邀请赛现场赛重现赛

    Swap There is a sequence of numbers of length nn, and each number in the sequence is different. Ther ...

  7. 随机序列[SHOI2016](找规律+线段树)

    传送门 这道题的题意就是给你n个数让你在每个数之间插入+.-.*三种运算符中的一种,然后算出一个答案,再把答案加起来. 这题肯定是不能暴力的(题目都告诉你了由3n-1种结果).我们先从小的情况枚举找一 ...

  8. hdu 3951 - Coin Game(找规律)

    这道题是有规律的博弈题目,,, 所以我们只需要找出规律来就ok了 牛人用sg函数暴力找规律,菜鸟手工模拟以求规律...[牢骚] if(m>=2) { if(n<=m) {first第一口就 ...

  9. HDU 5703 Desert 水题 找规律

    已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这 ...

随机推荐

  1. 集成支付宝SDK遇到的坑

    一.首先我先把集成过程说一下.小编想说的话:支付宝是我做支付中觉得坑最多的一个,各种编译不过,各种出问题. 废话不多说,进入主题:1.首先当前是下载官方SDK啦,当前你也可以通过cocopods进行导 ...

  2. 创建UILabel

    UILabelCreate.h #import <UIKit/UIKit.h> @interface UILabelCreate : UILabel /** * 创建UILabel 初始化 ...

  3. Hadoop 写SequenceFile文件 源代码

    package com.tdxx.hadoop.sequencefile; import java.io.IOException; import org.apache.hadoop.conf.Conf ...

  4. RequireJs 深入理解

    原文   http://www.tuicool.com/articles/jam2Anv RequireJs已经流行很久了,我们在项目中也打算使用它.它提供了以下功能: 声明不同js文件之间的依赖 可 ...

  5. javascript运动功能-分享到

    <script> //窗体载入,为div控件绑定事件 window.onload = function () { var div1 = document.getElementById('d ...

  6. 如何更改 Mac OS X 系统默认用户名

    说到 Mac 用户名估计有许多人都不知道在哪个地方修改,其实说简单也简单说麻烦也麻烦看你自己的需求.好比如果你只要用户名的登录更改,那是就非常简单的事了.下面这里就给大家介绍mac osx系统如何更改 ...

  7. iOS 面试题 2

    1.         描述应用程序的启动顺序. 1.程序入口main函数创建UIApplication实例和UIApplication代理实例 2.在UIApplication代理实例中重写启动方法, ...

  8. c++设计模式之策略模式

    概念:通过定义一系列封装的算法,使得调度者可以互相替换,此模式让算法的变化,不会影响到使用算法的客户. 特点: 1)根据不同的情况创建不同的对象. 2)每个对象的方法名相同,但实现却不同. 结构: 1 ...

  9. JavaScript 全局变量命名空间生成函数

    <script type="text/javascript"> var GLOBAL = {}; GLOBAL.namespace = function(str){ v ...

  10. 黑马程序员 1、C语言32个关键字整理分类

    ------Java培训.Android培训.iOS培训..Net培训.期待与您交流! ------ C语言一共有32个关键字 一.数据类型关键字(共20个) A.基本数据类型(5个)void :声明 ...