1559: Vive la Difference!

时间限制: 3 Sec  内存限制: 128 MB
提交: 18  解决: 14
[提交][状态][讨论版]

题目描述

Take any four positive integers: abcd. Form four more, like this:

a - b|,| b - c|,| c - d|,| d - a|

That is, take the absolute value of the differences of a with bb with cc 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 abc 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 ( 1abcd2, 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!(简单题)的更多相关文章

  1. HDU 1753 大明A+B(字符串模拟,简单题)

    简单题,但要考虑一些细节: 前导0不要,后导0不要,小数长度不一样时,有进位时,逆置处理输出 然后处理起来就比较麻烦了. 题目链接 我的代码纯模拟,把小数点前后分开来处理,写的很繁杂,纯当纪念——可怜 ...

  2. BZOJ 2683: 简单题

    2683: 简单题 Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 913  Solved: 379[Submit][Status][Discuss] ...

  3. 【BZOJ-1176&2683】Mokia&简单题 CDQ分治

    1176: [Balkan2007]Mokia Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 1854  Solved: 821[Submit][St ...

  4. Bzoj4066 简单题

    Time Limit: 50 Sec  Memory Limit: 20 MBSubmit: 2185  Solved: 581 Description 你有一个N*N的棋盘,每个格子内有一个整数,初 ...

  5. Bzoj2683 简单题

    Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 1071  Solved: 428 Description 你有一个N*N的棋盘,每个格子内有一个整数, ...

  6. 这样leetcode简单题都更完了

    这样leetcode简单题都更完了,作为水题王的我开始要更新leetcode中等题和难题了,有些挖了很久的坑也将在在这个阶段一一揭晓,接下来的算法性更强,我就要开始分专题更新题目,而不是再以我的A题顺 ...

  7. [BZOJ2683][BZOJ4066]简单题

    [BZOJ2683][BZOJ4066]简单题 试题描述 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要维护两种操作: 命令 参数限制 内容 1 x y A 1<=x ...

  8. 团体程序设计天梯赛-练习集L1-014. 简单题

    L1-014. 简单题 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 这次真的没骗你 —— 这道超级简单的题目没有任何输入. ...

  9. bzoj 4066: 简单题 kd-tree

    4066: 简单题 Time Limit: 50 Sec  Memory Limit: 20 MBSubmit: 234  Solved: 82[Submit][Status][Discuss] De ...

随机推荐

  1. jetcache:在Spring Boot中怎么玩?

  2. Ubuntu16.04 同时连接无线网络和以太网端口

    背景: 激光雷达VLP16通过以太网线连接电脑.在本博客所述的设置之前,一旦连接以太网线,本机(dell笔记本)的无线网络立即断开,即无法同时连接无线网络和以太网端口. 问题查找: 命令行  $ ip ...

  3. Springboot 构建http服务,返回的http行是'HTTP/1.1 200' 无状态码描述 客户端解析错误

    ————————————————————————————————————————— *** 响应的数据格式  HTTP/1.1 200 OK  Server: Apache-Coyote/1.1  A ...

  4. mysql忘记root登录密码

    没有过忘记密码的程序员是不完美的,对于Oracle忘记密码可以设置orapwdfile文件, Mysql其中一种方法是通过修改文件免密然后再进行密码的修改: 1.忘记密码 [root@leader ~ ...

  5. [Codeforce526F]:Pudding Monsters(分治)

    题目传送门 题目描述 由于各种原因,桐人现在被困在Under World(以下简称UW)中,而UW马上要迎来最终的压力测试——魔界入侵.唯一一个神一般存在的Administrator被消灭了,靠原本的 ...

  6. springCloud分布式事务实战(一)案例需求及实现步骤

    本文不对分布式事务原理进行探索,而是通过一个案例来说明如何使用分布式事务 案例需求:创建2个基于springCloud的微服务,分别访问不同的数据库:然后创建一个整合服务,调用微服务实现数据的保存到2 ...

  7. layui 获取select option value 获取text

    $.trim($("#processState").val()): //获取val $("#processState option:selected").tex ...

  8. 高级软件测试技术-小组任务分配和安排-Day01

    任务分配11-13 使用的工具 Jira 小组成员 华同学.郭同学.穆同学.沈同学.覃同学.刘同学 任务划分 1.撰写工具使用手册,要求在手册中至少说明如下内容: a. 该工具的基本情况,如名称,提供 ...

  9. 使用SharpZIpLib写的压缩解压操作类

    使用SharpZIpLib写的压缩解压操作类,已测试. public class ZipHelper { /// <summary> /// 压缩文件 /// </summary&g ...

  10. webpack.config.js文件

    与 package.json 配合使用 var path=require("path");var OpenBrowserPlugin = require('open-browser ...