HDU2277-Change the ball
来源:互联网 发布:爬虫软件官方下载 编辑:程序博客网 时间:2024/05/18 11:15
Change the ball
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 713 Accepted Submission(s): 281
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?
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 31 2 2
Sample Output
):2
Source
HDU 8th Programming Contest Site(1)
题意:有三种颜色的球(黄蓝黄),数量各不相同,现在给定每种球的个数,b并且有一种规则(拿起任意两种不同颜色的球他们的颜色会立马变成第三种颜色),问能否经过变换后所有的球都变成同一种颜色、需要的最少次数。
①有两个球的数量相等(或者是三个都相等)
②有一种球是另一种球数量的三倍(每改变一次,有一个球会增加2个,另两个会各减少1个,中间差了3,也就是说,只有是三的倍数的情况,三个球才能实现完全转化),这种条件就需要分情况了,因为可能是都转化为球最多的那个,也有可能是都转化成球数不是最多的那个(最少次数就为球最多的球数(可以等价为这种球一直在向别的转化))
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <algorithm>#include <cmath>#include <queue>#include <stack>#include <vector>#include <set>#include <map>using namespace std;int main(){ int a[3]; while(~scanf("%d%d%d",&a[0],&a[1],&a[2])) { sort(a,a+3); if(a[0]==a[1]||(a[1]-a[0])%3==0) printf ("%d\n",a[1]); else if(a[1]==a[2]||(a[2]-a[1])%3==0) printf ("%d\n",a[2]); else if(a[0]==a[2]||(a[2]-a[0])%3==0) printf ("%d\n",a[2]); else printf("):\n"); } return 0;}
0 0
- Change the ball--hdu2277
- HDU2277-Change the ball
- 2277 Change the ball
- Change the ball
- hdu-2277-Change the ball
- HDU-2277 Change the ball
- hdoj 2277 Change the ball
- HDU-2277 Change the ball
- 杭电2277 Change the ball
- hdoj 2277 Change the ball 【找规律】
- hdu 2277 Change the ball(找规律)
- hdoj 2277 Change the ball 【找规律】
- hdoj-2277-Change the ball【规律】
- hdoj 2277 Change the ball 【找规律】
- hdoj 2277 Change the ball【规律题】
- nyoj Change the ball 313 (技巧)
- HDOJ 题目2277 Change the ball(水题,规律)
- nyoj Change the ball 313 (技巧&思想)
- 【MCM-2017】2017年数学建模美赛题目原文及翻译-C (个人思路)
- 支付宝Unity
- 蒙特卡罗方法入门(阮一峰)
- 《计算机系统要素》学习笔记:第二章布尔运算
- spring security基础配置(一)
- HDU2277-Change the ball
- 俄罗斯方块游戏开发(VC++ mfc dialog模式)
- Laravel 中点赞功能实现
- GCC编译过程
- 学习记录2
- 最大公约数和最小公倍数 分解质因数 完全平方数
- 用C语言实现 坐标管理系统(类似于学生管理系统的功能)
- 获取全部存储设备路径
- 如何保证矩阵计算的精确度:backward stable & well conditioned