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. 笔试算法题(24):找出出现次数超过一半的元素 & 二叉树最近公共父节点

    出题:数组中有一个数字出现的次数超过了数组长度的一半,请找出这个数字: 分析: 解法1:首先对数组进行排序,时间复杂度为O(NlogN),由于有一个数字出现次数超过了数组的一半,所以如果二分数组的话, ...

  2. MySQL异常:Caused by: com.mysql.jdbc.exceptions.MySQLTimeoutException: Statement cancelled due to timeout or client request

    Caused by: com.mysql.jdbc.exceptions.MySQLTimeoutException: Statement cancelled due to timeout or cl ...

  3. java IO流 内容整理

    在java中,对数据的输入和输出操作以流的方式进行.(注:对文件的操作用io.File类,但不能对文件中的内容进行操作) 一.IO流的分类: 按数据流的方向不同,可以分为输入流和输出流: 按处理数据的 ...

  4. http2提升效率的几个点

    1.二进制传输,消息的解析效率更高 2.头部数据压缩,传输效率更高 3.多路复用,可以让请求并发执行 4.服务器推送,可以主动推送数据到浏览器 http2加载图片demo:https://http2. ...

  5. Bootstrap-Table 总结

    Bootstrap-Table 总结 jQuery Java Bootstrap-Table JS文件 传参:直接将需要的参数置于 queryParams 方法中,例如 line:formData注意 ...

  6. [Android] java代码无错误,但跳转失败

    今天在调代码的时候,出现了这样的问题,我晕了半天,才找到解决办法. 查看日志发现:Initialize Binary Program Cache: Load Failed 从来没见过这种问题,Java ...

  7. 输出一定范围unicode对应符号

    #本程序没有考虑对0x的处理,请勿输入,直接输入16进制位即可 begin = input("起始点:") end = input("结束点:") b_int0 ...

  8. Caused by: java.io.IOException: 您的主机中的软件中止了一个已建立的连接。

    异常详情 2017-07-16 10:55:26,218 ERROR [500.jsp] - java.io.IOException: 你的主机中的软件中止了一个已建立的连接. org.apache. ...

  9. python——文件管理

    文件操作分为读.写.修改 一.读文件 f = open(file='D:/工作日常/兼职白领学生空姐模特护士联系方式.txt',mode='r',encoding='utf-8') data = f. ...

  10. SQL Server 2016 CTP3.2 开荒 Reporting Service 篇

    仅仅是开荒资源页,反正过不了多久就会有新的CTP. 下面是MSDN I Tell you 提供的 不过是中文,个人不是很建议,因为现在大多的资源页都是英文的ed2k://|file|cn_sql_se ...