Steps


Time Limit: 2 Seconds      Memory Limit: 65536 KB


One steps through integer points of the straight line. The length of a step must be nonnegative and can be by one bigger than, equal to, or by one smaller than the length of the previous
step. 



What is the minimum number of steps in order to get from x to y? The length of the first and the last step must be 1.

Input

For each test case, a line follows with two integers: 0 <= x <= y < 2^31.

Output

For each test case, print a line giving the minimum number of steps to get from x to y.

Sample Input



45 48

45 49

45 50

Sample Output



3

3

4


Source: University of Waterloo Local Contest 2000.01.29

你  离  开  了  ,  我  的  世  界  里  只  剩  下  雨  。  。  。

#include<iostream>
using namespace std;
int main()
{
long a,b,d;
int c,step;
while(cin>>a>>b)
{
d=b-a,c=1,step=0;
while(1)
{
if(d<2*c)break;
else
{
d=d-2*c;
step+=2;
c++;
}
}
if(d>c)step+=2;
else if(d<=0)step+=0;
else step+=1;
cout<<step<<endl;
}
return 0;
}

ZOJ 1871:Steps的更多相关文章

  1. POJ 2590 Steps (ZOJ 1871)

    http://poj.org/problem?id=2590 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1871 题目大 ...

  2. ZOJ 1414:Number Steps

    Number Steps Time Limit: 2 Seconds      Memory Limit: 65536 KB Starting from point (0,0) on a plane, ...

  3. ZOJ 1301 The New Villa (BFS + 状态压缩)

    题意:黑先生新买了一栋别墅,可是里面的电灯线路的连接是很混乱的(每个房间的开关可能控制其他房间,房间数<=10),有一天晚上他回家时发现所有的灯(除了他出发的房间)都是关闭的,而他想回卧室去休息 ...

  4. ZOJ 3890 Wumpus

    Wumpus Time Limit: 2 Seconds      Memory Limit: 65536 KB One day Leon finds a very classic game call ...

  5. ZOJ Problem Set - 3593 拓展欧几里得 数学

    ZOJ Problem Set - 3593 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3593 One Person ...

  6. ZOJ 2477 Magic Cube(魔方)

    ZOJ 2477 Magic Cube(魔方) Time Limit: 2 Seconds      Memory Limit: 65536 KB This is a very popular gam ...

  7. ZOJ 3992 One-Dimensional Maze(思维题)

    L - One-Dimensional Maze Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & % ...

  8. ZOJ 3781 Paint the Grid Reloaded(BFS+缩点思想)

    Paint the Grid Reloaded Time Limit: 2 Seconds      Memory Limit: 65536 KB Leo has a grid with N rows ...

  9. ZOJ - 3890 Wumpus(BFS基础题)

    Wumpus Time Limit: 2 Seconds      Memory Limit: 65536 KB One day Leon finds a very classic game call ...

随机推荐

  1. 全国高校绿色计算大赛 预赛第二阶段(Python)

    第1关统计分数的麻烦 class Task: def get_lost_scores(self, scores): s = "" index = [1 for i in range ...

  2. NOIp十连测 涂色游戏

    [问题描述]小A 和小B 在做游戏.他们找到了一个n 行m 列呈网格状的画板.小A 拿出了p 支不同颜色的画笔,开始在上面涂色.看到小A 涂好的画板,小B 觉得颜色太单调了,于是把画板擦干净,希望涂上 ...

  3. KBE实践——登录案例

    目录 服务器 ``` void maini(){ printf("hello world"); } ``` 最小资产库创建 entity配置 实体的Python实现 创建第一个空间 ...

  4. Python 软件开发目录规范

    目录规范: ATM  #工程文件夹 ------| bin  #用来存放可执行文件的 |----  start.py conf  #用来存放配置信息的 |----  settings.py lib  ...

  5. 安装lnmp

    一.yum安装php 1.更新更新yum源:rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rp ...

  6. ubuntu 14.04上源码编译安装php7

    wget https://downloads.php.net/~ab/php-7.0.0alpha2.tar.bz2 //用winscp把下载好的文件上传到网站中 tar jxf php-7.0.0a ...

  7. windows下mysql使用实录

    之前密码忘了,卸载重装,配置好环境变量,登录,成功 操作命令可参考http://www.runoob.com/mysql/mysql-tutorial.html 这里只列举了我需要用到的命令 登录:m ...

  8. python之抽象 2014-4-6

    #抽象 8.40am-1.懒惰即美德2.抽象和结构3.创建函数 内建的callable 函数可以判定函数是否可以调用 >>> import math >>> x=1 ...

  9. 九度oj 题目1196:成绩排序

    题目1196:成绩排序 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5192 解决:1792 题目描述: 用一维数组存储学号和成绩,然后,按成绩排序输出. 输入: 输入第一行包括一个整数 ...

  10. expdp,impdp,include,exclude

    The examples below are based on:- the demo schema SCOTT that is created with script: $ORACLE_HOME/rd ...