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. ios想要取消执行延时调用的方法

    想要取消执行延时调用的方法: [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(hideDia ...

  2. Git源码管控规范

    Git分支示意圖 Master:主分支.形成稳定的版本时,才将代码合并到Master分支 Relase:网站发布的分支.通过验证的Bug和功能需求,才合并到Release分支,并将稳定的版本进行备份 ...

  3. 【软件技巧】Sublime Text为不同语法定义不同高亮

    Sublime Text默认的语法高亮已经非常美丽了,可是对于个别语言还是有些不爽. 默认高亮规则叫Monokai,能够从Preferences->Settings - Default中看到: ...

  4. [Git] --no-verify

    Somtimes, the project might set the commit message guide line, if your commit doesn't meet the requi ...

  5. 用ajaxFileUpLoad上传文件不能正确取得返回值的问题

    刚開始没有认为ajax请求的dataType參数的重要性,用了ajaxFileUpLoad插件后,假设页面代码例如以下: fileElementId : ['imageToUpload'], url ...

  6. 阿里云部署Docker(5)----管理和公布您的镜像

    出到这节,我在百度搜索了一下"阿里云部署Docker",突然发现怎么会有人跟我写的一样呢?哦,原来是其它博客系统的爬虫来抓取,然后也不会写转载自什么什么的.所以,我最终明确为什么那 ...

  7. iBatis2之SqlMap配置总结(18条)

    iBatis2之SqlMap配置总结(18条)   SqlMap的配置是iBatis中应用的核心.这部分任务占据了iBatis开发的70的工作量. 1.命名空间:   <sqlMap names ...

  8. 软件设计之UML—UML中的六大关系

    http://www.cnblogs.com/hoojo/p/uml_design.html

  9. HDU 5735 - Born Slippy

    题意: 一棵 n 个节点的根树,i 节点权重 wi 对每一个节点s,找到这样一个长 m 的标号序列 v : 1. vi是vi-1 的祖先 2. f[s] = w[vi] + ∑(i=2, m) (w[ ...

  10. python调webservice和COM接口

    调webservice # -*- coding: cp936 -*- from suds.client import Client url = 'http://192.168.50.165/port ...