题目链接:http://poj.org/problem?id=2590
解题思路:
水题,找规律。
AC代码:
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int x,y,step;
scanf("%d%d",&x,&y);
int t=y-x;
int a=sqrt(t*1.0);
int b=a*(a+1);
if(b>t)
{
if(a*(a-1)+a<t)
step=2*a;
else
step=2*a-1;
}
else if(t-b==0)
step=2*a;
else if(t-b>a)
step=2*a+2;
else
step=2*a+1;
printf("%d\n",step);
}
return 0;
}