HDU 2277 Change the ball
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2277
Change the ball
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 694 Accepted Submission(s):
272
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?
R(1<=Y,B,R<=1000),indicate the number refered above.
complete the assignment. If not, output the symbol “):”.
①有两个球的数量相等(或者是三个都相等)
②有一种球是另一种球数量的三倍(每改变一次,有一个球会增加2个,另两个会各减少1个,中间差了3,也就是说,只有是三的倍数的情况,三个球才能实现完全转化),这种条件就需要分情况了,因为可能是都转化为球最多的那个,也有可能是都转化成球数不是最多的那个(最少次数就为球最多的球数(可以等价为这种球一直在向别的转化))
AC代码:
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int a[];
while (~scanf ("%d %d %d",&a[],&a[],&a[]))
{
sort (a+,a++);
if ( a[] == a[] || (a[] - a[]) % == ) //先看是否能把最少的转化成多的
printf ("%d\n",a[]); //如果可以的话,实际上是 a[2] 一直向 a[1]和 a[3]转化
else if ( a[] == a[] || (a[] - a[]) % == )
printf ("%d\n",a[]); //结合上一种,这一种也可以理解
else if ( a[] == a[] || (a[] - a[]) % == )
printf ("%d\n",a[]); //实际上,这种情况完全可以和上一种合并,但是为了程序的清楚就分开了
//else if ( a[2] == a[3] || (a[3] - a[2]) % 3 == 0 || a[1] == a[3] || (a[3] - a[1]) % 3 == 0 )
// printf ("%d\n",a[3]);
//最后两个 else if 可以合并成这样
else
printf ("):\n");
}
return ;
}
HDU 2277 Change the ball的更多相关文章
- hdoj 2277 Change the ball【找规律】
Change the ball Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu 1556:Color the ball(第二类树状数组 —— 区间更新,点求和)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1556:Color the ball(线段树,区间更新,经典题)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- Change the ball(找规律)
Change the ball Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- FZU oj 2277 Change 树状数组+dfs序
Problem 2277 Change Time Limit: 2000 mSec Memory Limit : 262144 KB Problem Description There is ...
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- hdu 1199 Color the Ball
http://acm.hdu.edu.cn/showproblem.php?pid=1199 Color the Ball Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 1556 Color the ball (数状数组)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- 线段树(求单结点) hdu 1556 Color the ball
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
随机推荐
- C# 从CIL代码了解委托,匿名方法,Lambda 表达式和闭包本质
前言 C# 3.0 引入了 Lambda 表达式,程序员们很快就开始习惯并爱上这种简洁并极具表达力的函数式编程特性. 本着知其然,还要知其所以然的学习态度,笔者不禁想到了几个问题. (1)匿名函数(匿 ...
- 《BI那点儿事》SQL Server 2008体系架构
Microsoft SQL Server是一个提供了联机事务处理.数据仓库.电子商务应用的数据库和数据分析的平台.体系架构是描述系统组成要素和要素之间关系的方式.Microsoft SQL Serve ...
- 《BI那点儿事》数据流转换——条件性拆分
根据条件分割数据是一个在数据流中添加复杂逻辑的方法,它允许根据条件将数据输出到其他不同的路径中.例如,可以将TotalSugar< 27.4406的输出到一个路径,TotalSugar > ...
- xml资源getStringArray(R.array.xxx)方法
在res/values/下新建menu_names.xml 代码如下: <?xml version="1.0" encoding="utf-8"?> ...
- Deep Learning 17:DBN的学习_读论文“A fast learning algorithm for deep belief nets”的总结
1.论文“A fast learning algorithm for deep belief nets”的“explaining away”现象的解释: 见:Explaining Away的简单理解 ...
- Linux 远程桌面 访问 WIndows
1. Debain 系列 linux sudo aptitude install rdesktop 2. Connect rdesktop <hostname> -r sound:off ...
- c++ 在windows下建立目录
#include <direct.h> #include <stdlib.h> #include <stdio.h> int main( void ) { ) { ...
- js String对象中常用方法小结(字符串操作)
1.charCodeAt方法返回一个整数,代表指定位置字符的Unicode编码. strObj.charCodeAt(index) 说明: index将被处理字符的从零开始计数的编号.有效值为0到字符 ...
- U-Boot
U-Boot U-Boot,全称 Universal Boot Loader,是遵循GPL条款的开放源码项目.从FADSROM.8xxROM.PPCBOOT逐步发展演化而来.其源码目录.编译形式与Li ...
- C 风格字符串和strcpy方法的实现
C语言是面向过程的,所以它并没有所谓封装好的功能强大的string.但是麻雀虽小五脏俱全.在C中,我们一般用 const char* 类型来定义一个字面型字符串. 首先我们了解下C中的基本指针.指针是 ...