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. 数据库中简单的增删改查(CRUD)

    一切都是基于数据,而对数据的管理都离不开数据库.最近学到数据库的简单操作,所以写下这篇文章,总结一下学习到的知识.浅陋之处,多多见谅. 补充一下:一直弄不清SQL Server,Mysql ,以及Or ...

  2. Angular Textarea 高度自动变化

    很多前端开发的朋友可能都会遇到textarea 输入框的高度不能自动随着用户的输入变化的问题,今儿小生也遇到了, 并通过网络上的信息解决了这个问题,于是将解决方法贴上,以作备忘. directiveA ...

  3. java与.net比较学习系列(6) 数组

    这一篇文章要总结的内容是数组,数组可以简单地看成是同种数据类型变量的集合,它在我们的开发中经常用到,我们主要从以下几个方面进行总结: 1,数组的创建和初始化 2,数组的访问和遍历 3,数组的总结 数组 ...

  4. magic Ajax使用以及注意事项

    以下是引用片段:一.概述    现在Ajax技术正如火如荼的在Internet上发展着.而面对我们之前开发的ASP.NET1.1的Web项目,类似于下拉框等联动也需要啪啪啪的不断刷新,的确影响到了用户 ...

  5. webservice和.net remoting浅谈

    服务器端向客户端发送一个进程编号,一个程序域编号,以确定对象的位置.   webservice和.net remoting都是用来通信的框架,它们最大的优点是可以像调用本地对象一样调用远程对象,比如: ...

  6. .c_str()/atoi()/

    1. c_str是把string类型强制转换为const string 2. atpi(): Convert string to integer --Parses the C-string str i ...

  7. jetty 8.1.8 PWC6345: There is an error in invoking javac. A full JDK (not just JRE) is required

    应该是jdk和jre配置问题,建议看看这个博客:http://blog.csdn.net/nba_2011/article/details/7219750里边查看配置方法很清楚

  8. OER 7451 in Load Indicator : Error Code = OSD-04500:指定了非法选项

    alert 日志错误OER 7451 in Load Indicator : Error Code = OSD-04500:指定了非法选项 Sun Apr 22 11:15:51 2012 OER 7 ...

  9. Asp.Net通过SignalR实现IM即时通讯

    前言:SignalR是一种针对H5中WebSocket的解决方案,可以实现在不支持H5的浏览器中实现IM 后端: step 1:通过NuGet安装SignalR step 2:新建一个类继承于Hub, ...

  10. new String(byte[])和byte[]toString() 的区别

    byte[]字节数组的toString()获得的字符串和使用new String(byte[])构造一个新的字符串,这两个字符串是不一样的.Java对象都继承于Object,Object中提供了toS ...