Steps
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 and Output
Input consists of a line containing n, the number of test cases. For each test case, a line follows with two integers: 0![$ \le$](http://uva.onlinejudge.org/external/8/846img1.png)
![$ \le$](http://uva.onlinejudge.org/external/8/846img1.png)
Sample Input
3 45 48 45 49 45 50
Sample Output
3 3 4解决方案:从两边逼近会发现规律。
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int Start,End;
int n;
scanf("%d",&n);
while(n--)
{
scanf("%d%d",&Start,&End);
int Count=1,step=0;
for(;;)
{
if(Start>=End)
{
cout<<2*step<<endl;break;
}
else if(End-Start<=Count)
{
cout<<2*step+1<<endl;break;
}
else {
Start+=Count;
End-=Count;
Count++;
step++;
}
}
}
return 0;
}