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 ...
随机推荐
- LabVIEW有限状态机
顺序模式是我们最先接触,也是最基本的一种编程模式, 程序按照固定的顺序依次执行,结束(如图1) 但在很多情况下,静态的顺序模式并不能满足我们编程的要求,我们需要更有效地动态结构来实时改变程序的执行顺序 ...
- 关于JS的数据类型的一些见解
关于js里的数据类型这块,说下个人对它的一些见地 js中的数据类型可以归类两类, 简单数据类型:string,number,boolean,null,undefined 复杂数据类型:object 其 ...
- Div中高度自适应增长方法
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- IOS开发之WIFI及IP相关
获取手机设备的IP信息: #import <ifaddrs.h> #import <arpa/inet.h> // Get IP Address - (NSString *)g ...
- nginx 负载均衡策略
nginx 负载均衡策略 1. 轮询轮询方式是nginx负载均衡的默认策略,根据每个server的权重值来轮流发送请求,例如:upstream backend {server backend1.e ...
- C++成员变量内存对齐问题,ndk下非对齐的内存访问导致BUS_ADRALN
同样的代码,在vs下运行正常,在android ndk下却崩溃: signal 7(SIGBUS),code 1 (BUS_ADRALN),fault addr 0xe6b82793 Func(sho ...
- 转json using指令
using Newtonsoft.Json;using Newtonsoft.Json.Converters; string result = JsonConvert.SerializeObject( ...
- Mybatis 批量insert
@Override public int insertHouseTypeScene(int htid, String name, String icon,int sort, List<House ...
- C语言混乱代码大赛
main() {printf(&unix["\021%six\012\0"], (unix)["have"] + "fun" - 0 ...
- 安装mongodb
安装mongodb的时候遇到一些麻烦 首先将安装包下下来 安装的是windows版本的 将bin文件夹加入环境变量后通过mongod和mongo指令就可以进行操作,很方便 用指令mongod --db ...