HDUSTOJ-1559 Vive la Difference!(简单题)
1559: Vive la Difference!
时间限制: 3 Sec 内存限制: 128 MB
提交: 18 解决: 14
[提交][状态][讨论版]
题目描述
Take any four positive integers: a, b, c, d. Form four more, like this:
That is, take the absolute value of the differences of a with b, b with c, c with d, and d with a. (Note that a zero could crop up, but they'll all still be non-negative.) Then, do it again with these four new numbers. And then again. And again. Eventually, all four integers will be the same. For example, start with 1,3,5,9:
1 3 5 9
2 2 4 8 (1)
0 2 4 6 (2)
2 2 2 6 (3)
0 0 4 4 (4)
0 4 0 4 (5)
4 4 4 4 (6)
In this case, the sequence converged in 6 steps. It turns out that in all cases, the sequence converges very quickly. In fact, it can be shown that if all four integers are less than 2n, then it will take no more than 3*n steps to converge!
Given a, b, c and d, figure out just how quickly the sequence converges.
输入
There will be several test cases in the input. Each test case consists of four positive integers on a single line ( 1
a, b, c, d
2, 000, 000, 000), with single spaces for separation. The input will end with a line with four 0's.
输出
For each test case, output a single integer on its own line, indicating the number of steps until convergence. Output no extra spaces, and do not separate answers with blank lines.
样例输入
1 3 5 9
4 3 2 1
1 1 1 1
0 0 0 0
样例输出
6
4
0
这道题原来以为直接搞会超时的,结果没超时,而且还很充裕
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio> int main(){
int a, b, c, d;
while(scanf("%d %d %d %d", &a, &b, &c, &d) == && (a + b + c + d)){
int cnt = ;
while(true){
if(a == b && b == c && c ==d) break;
int tmp = a;
a = abs(a - b);
b = abs(b - c);
c = abs(c - d);
d = abs(d - tmp);
cnt++;
}
printf("%d\n", cnt);
}
}
HDUSTOJ-1559 Vive la Difference!(简单题)的更多相关文章
- HDU 1753 大明A+B(字符串模拟,简单题)
简单题,但要考虑一些细节: 前导0不要,后导0不要,小数长度不一样时,有进位时,逆置处理输出 然后处理起来就比较麻烦了. 题目链接 我的代码纯模拟,把小数点前后分开来处理,写的很繁杂,纯当纪念——可怜 ...
- BZOJ 2683: 简单题
2683: 简单题 Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 913 Solved: 379[Submit][Status][Discuss] ...
- 【BZOJ-1176&2683】Mokia&简单题 CDQ分治
1176: [Balkan2007]Mokia Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 1854 Solved: 821[Submit][St ...
- Bzoj4066 简单题
Time Limit: 50 Sec Memory Limit: 20 MBSubmit: 2185 Solved: 581 Description 你有一个N*N的棋盘,每个格子内有一个整数,初 ...
- Bzoj2683 简单题
Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 1071 Solved: 428 Description 你有一个N*N的棋盘,每个格子内有一个整数, ...
- 这样leetcode简单题都更完了
这样leetcode简单题都更完了,作为水题王的我开始要更新leetcode中等题和难题了,有些挖了很久的坑也将在在这个阶段一一揭晓,接下来的算法性更强,我就要开始分专题更新题目,而不是再以我的A题顺 ...
- [BZOJ2683][BZOJ4066]简单题
[BZOJ2683][BZOJ4066]简单题 试题描述 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要维护两种操作: 命令 参数限制 内容 1 x y A 1<=x ...
- 团体程序设计天梯赛-练习集L1-014. 简单题
L1-014. 简单题 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 这次真的没骗你 —— 这道超级简单的题目没有任何输入. ...
- bzoj 4066: 简单题 kd-tree
4066: 简单题 Time Limit: 50 Sec Memory Limit: 20 MBSubmit: 234 Solved: 82[Submit][Status][Discuss] De ...
随机推荐
- 页面渲染机制(一、DOM和CSSOM树的构建)
1.HTML的加载 HTML是一个网页的基础,下载完成后解析 2.其他静态资源加载 解析HTML时,发现其中有其他外部资源链接比如CSS.JS.图片等,会立即启用别的线程下载. 但当外部资源是JS时, ...
- sql len函数 CASE WHEN
SELECT LEN('SQL Server LEN') length, LEN('SQL Server LEN ') length_with_trailing_blanks; SELECT (CAS ...
- jquery扩展方法(表单数据格式化为json对象)
1.jquery扩展方法(表单数据格式化为json对象) <script type="text/javascript"> // 将表单数据序列化为一个json对象,例如 ...
- UML——用例视图
用例视图中交互功能部分被称为用例. 参与者 作为外部用户与系统发生交互作用,这是参与者的特征. 在系统的实际运作中,一个实际用户可能对应系统的多个参与者.不同的用户也可以只对应于一个参与者,从 ...
- Selenium 多表单(frame/iframe)切换
frame标签有frameset.frame.iframe三种,frameset跟其他普通标签没有区别,不会影响到正常的定位,而frame与iframe需要切换进去才能定位到其中的元素 比如下面这个网 ...
- Hive数据导入Elasticsearch
Elasticsearch Jar包准备 所有节点导入elasticsearch-hadoop-5.5.1.jar /opt/cloudera/parcels/CDH-5.12.0-1.cdh5.12 ...
- (转)搭建自己的Nuget服务器
转:https://www.cnblogs.com/knowledgesea/p/5500954.html 序言 你们公司有没有好多项目,有没有好多类库,你们的类库是在tfs中管理,还是svn或者gi ...
- js测试用
一,大纲 二,目录二 三,目录三
- LeetCode_1116.打印零与奇偶数(多线程)
LeetCode_1116 LeetCode-1116.打印零与奇偶数 假设有这么一个类: class ZeroEvenOdd { public ZeroEvenOdd(int n) { ... } ...
- easyhook源码分析一
easyhook简要说明: easyhook是一个开源的hook库(http://easyhook.github.io/),其支持托管代码(.NET)和非托管代码(C/C++)hook,这里只分析了其 ...