ZOJ 1871:Steps

网友投稿 210 2022-08-31

ZOJ 1871:Steps

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

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

#includeusing 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<

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:POJ 2505:A multiplication game
下一篇:「忠于所爱」的背后,CBA开启营销新格局!
相关文章

 发表评论

暂时没有评论,来抢沙发吧~