Change the ball

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

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
题意:给三个小球,其中两个不一样颜色的碰一下这两个小球可以变成第三种小球的颜色,问最少需要几步可以让所有的
        球变成同一种颜色
题解:1、当有两种颜色的小球个数相等时步数就等于这相等个数小球的个数
        2、当其中有一个数与另一个数的差是3的倍数时也可以答案是做差的两个数中较大的那个
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int n,m,j,i,t;
int a[10];
int x,y;
while(scanf("%d%d%d",&a[0],&a[1],&a[2])!=EOF)
{
sort(a,a+3,cmp);
if(a[0]==a[1]||a[1]==a[2]||(a[1]-a[2])%3==0)
printf("%d\n",a[1]);
else if((a[0]-a[1])%3==0||(a[0]-a[2])%3==0)
printf("%d\n",a[0]);
else
printf("):\n");
}
return 0;
}

  

hdoj 2277 Change the ball【找规律】的更多相关文章

  1. HDU 2277 Change the ball

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2277 Change the ball Time Limit: 2000/1000 MS (Java/O ...

  2. Change the ball(找规律)

    Change the ball Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  3. 找规律/数位DP HDOJ 4722 Good Numbers

    题目传送门 /* 找规律/数位DP:我做的时候差一点做出来了,只是不知道最后的 is_one () http://www.cnblogs.com/crazyapple/p/3315436.html 数 ...

  4. 数学--数论--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 ...

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

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

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

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

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

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

  8. 计蒜客 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 ...

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

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

随机推荐

  1. struts2 测试错题解析

    解析:$.parseJSON()方法是将字符串转换成Json类型数据,$.getJSON()方法是获取JSON数据,两者不用联合使用. 解析: A:ActionContext接口没有getReques ...

  2. UVA 10817 Headmaster's Headache(DP +状态压缩)

    Headmaster's Headache he headmaster of Spring Field School is considering employing some new teacher ...

  3. [Lua]索引极致,form.lua

    local form = {_tag = 'form'} function form.build(tag, super) local target = { _tag = tag, _super = s ...

  4. jQuery慢慢啃之ajax(九)

    1.jQuery.ajax(url,[settings])//通过 HTTP 请求加载远程数据 如果要处理$.ajax()得到的数据,则需要使用回调函数.beforeSend.error.dataFi ...

  5. angular 控制器之间值得传递

    <div ng-controller="ParentCtrl"> <!--父级--> <div ng-controller="SelfCtr ...

  6. 关于【键鼠<局域网>共享软件:synergy】install

    Installation 另外,本人在centos6.5环境下作为server运行时,遇到一个问题,synergy1.5随着系统升级居然变成了1.3X,所以如果遇到类似问题,请您先用 rpm -qa ...

  7. ASP.NET MVC轻教程 Step By Step 9——分页

    现在我们要把Index视图的留言信息进行分页显示. Step 1. 创建路由 我们希望以类似地址http://localhost:41583/Page1来表示第一页,Page2表示第二页,以此类推.在 ...

  8. 《深入剖析Tomcat》阅读(二)

    Tomcat是基于Sun公司标准的开源Servlet容器. Servlet是什么? Servlet(Server Applet),全称Java Servlet,未有中文译文.是用Java编写的服务器端 ...

  9. (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO

    http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...

  10. sqlserver 字符串处理函数解释

    1.ASCII()返回字符表达式最左端字符的ASCII 码值.在ASCII()函数中,纯数字的字符串可不用‘’括起来,但含其它字符的字符串必须用‘’括起来使用,否则会出错.2.CHAR()将ASCII ...