Steps
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7872   Accepted: 3612

Description

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

Input consists of a line containing n, the number of test cases.

Output

For each test case, a line follows with two integers: 0 <= x <= y < 2^31. For each test case, print a line giving the minimum number of steps to get from x to y.

Sample Input

3
45 48
45 49
45 50

Sample Output

3
3
4

Source

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

#include<iostream>
using namespace std;
int main()
{
long a,b,d;
int n,c,step;
cin>>n;
while(n--)
{
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;
}

POJ 2590:Steps的更多相关文章

  1. POJ 2590 Steps (ZOJ 1871)

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

  2. POJ 2590

    #include<iostream> #include<algorithm> #define MAXN 1000000 using namespace std; unsigne ...

  3. POJ 1663:Number Steps

    Number Steps Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13758   Accepted: 7430 Des ...

  4. POJ 1663:Number Steps

    Number Steps Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13664   Accepted: 7378 Des ...

  5. 上POJ刷题

    Online Judge系统      Online Judge系统(简称OJ)是一个在线的判题系统.用户可以在线提交给定问题的多种程序(如C.C++.Pascal.Java)源代码,系统对源代码进行 ...

  6. POJ 3009 Curling 2.0【带回溯DFS】

    POJ 3009 题意: 给出一个w*h的地图,其中0代表空地,1代表障碍物,2代表起点,3代表终点,每次行动可以走多个方格,每次只能向附近一格不是障碍物的方向行动,直到碰到障碍物才停下来,此时障碍物 ...

  7. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

  8. POJ 2486 Apple Tree

    好抽象的树形DP......... Apple Tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6411 Accepte ...

  9. POJ 2195 Going Home 最小费用最大流 尼玛,心累

    D - Going Home Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

随机推荐

  1. MYSQL每日一学 - 时间间隔表达式

    参考链接:https://dev.mysql.com/doc/refman/5.7/en/expressions.html Interval表达式(Temporal intervals)的使用 Int ...

  2. js中给正则传参、传递变量

    js中验证字符串有时需要用到正则表达式,一般情况下直接写正则进行验证就行. 但是遇到需要把部分正则作为参数传递就麻烦一点,需要用到RegExp()对象. <script type="t ...

  3. 数据结构代码实现之队列的链表实现(C/C++)

    上班闲着无聊,一直想着要开始写博客,但又不知道写什么.最近又回顾了下数据结构的知识,那就从数据结构开始吧. 前言 关于C语言结构体的知识以及队列的特性请读者自行了解,此处不做过多解释,嘻嘻. 同时此篇 ...

  4. Poj 2187 凸包模板求解

    Poj 2187 凸包模板求解 传送门 由于整个点数是50000,而求凸包后的点也不会很多,因此直接套凸包之后两重循环即可求解 #include <queue> #include < ...

  5. 【转】jquery 注册事件的方法

    原文链接:http://outofmemory.cn/code-snippet/2123/jquery-zhuce-event-method 1.使用事件名来绑定,可用的事件名有 change,cli ...

  6. Springboot和SpringMVC区别

    Springboot和SpringMVC区别----http://www.cnblogs.com/xdyixia/p/9279644.html

  7. 【扫描线】Educational Codeforces Round 4 D. The Union of k-Segments

    http://codeforces.com/contest/612/problem/D [题解] http://blog.csdn.net/strokess/article/details/52248 ...

  8. 走进矩阵树定理--「CodePlus 2017 12 月赛」白金元首与独舞

    n,m<=200,n*m的方阵,有ULRD表示在这个格子时下一步要走到哪里,有一些待决策的格子用.表示,可以填ULRD任意一个,问有多少种填法使得从每个格子出发都能走出这个方阵,答案取模.保证未 ...

  9. 硬盘安装Win 7系统Windows 7 系统硬盘安装教程(图解)

    目前,win 7的市场占有率即将超过XP成为了第一大系统,很多人也用上了win 7,你是不是也还是徘徊呢?是否因为XP用习惯了,或者是不会安装 win7呢?win7安装其实不麻烦,不管是什么系统,安装 ...

  10. 一个1x1px大小Data/Base64数据的gif透明图片

    <img src="data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNg ...