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. 22Spring基于配置文件的方式配置AOP

    直接看代码: package com.cn.spring.aop.impl; //加减乘除的接口类 public interface ArithmeticCalculator { int add(in ...

  2. 02--Activiti初始化表

    初始化数据库 方法一:执行sql脚本文件activiti-5.13\database\create\activiti.mysql.create.*.sql文件 方法二:代码创建(有流程自然就有表) p ...

  3. 3.2.8 sed 的运作

        sed 的工作方式相当直接.命令行上的每个文件会依次打开与读取.如果没有文件,则使用标准输入,文件名“-”(单个破折号)可用于表示标准输入.       [many@avention Desk ...

  4. 得到JavaWeb项目在Tomcat中的运行路径

    获得绝对路径 ··· File file= new File(path); System.out.println(file.getAbsolutePath()); ··· 获得Tomcat路径 这是一 ...

  5. xcap发包工具的简单使用2(发送报文)

    上一篇文章介绍了如何构造报文,现在简单讲一下发送报文的步骤 1.获取接口列表 点击主界面工具栏中的“刷新列表”按钮(或对应菜单“interface->Reference interfaces”) ...

  6. JavaScript判断页面是否已经加载完毕

    做页面时经常会遇到当前页面加载完成后,执行某些初始化工作.这时候就要知道如何判断页面(包括IFRAME)已经加载完成,代码如下: < script language = "javasc ...

  7. [bzoj4520][Cqoi2016]K远点对_KD-Tree_堆

    K远点对 bzoj-4520 Cqoi-2016 题目大意:已知平面内 N 个点的坐标,求欧氏距离下的第 K 远点对. 注释:$1\le n\le 10^5$,$1\le k\le 100$,$k\l ...

  8. restful接口就是url嘛,通过http请求发起访问。那接口进行监控,就可以监控这个restful url嘛

    EasyAPI接口管理系统 专注API接口监控,让您的API接口更稳定,与APP更紧密 + 购买监控服务 接口性能分析 分析App对应的API接口请求性能,包含HTTP响应时间.吞吐率.HTTP错误率 ...

  9. 怎样载入指定路径的Logback.xml

    今天想外置logback.xml,谢了例如以下代码 File logbackFile = new File("./conf/logback.xml"); if (logbackFi ...

  10. zabbix学习系列之配置邮件告警

    整体思路是:添加监控项-->配置触发器(达到设定的阈值就触发)-->配置动作(将某个触发器绑定到某个动作,达到某个阈值,触发器触发的时候,通过邮件发送告警信息给某个用户) 配置触发器 创建 ...