POJ 2590:Steps
2016-02-01 20:24
344 查看
Steps
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
Sample Output
Source
Waterloo local 2000.01.29
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 7872 | Accepted: 3612 |
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
Waterloo local 2000.01.29
你 离 开 了 , 我 的 世 界 里 只 剩 下 雨 。 。 。
#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; }
相关文章推荐
- java语言读取xml文本中的内容
- JavaScript菜鸟教程 grammar
- Java抢红包小程序
- java IO回想小结
- hdoj 1527取石子游戏
- 初识算法
- Qt 富文本处理(QTextDocument和QTextBlock和QTextFrame和QTextTable和QTextList和QTextDocument)
- 九度[1085]求root(N,K)
- (5)调度器(scheduler)
- 03-lvs-persistence
- ubuntu上面装matlab
- 让你的 Qt 桌面程序看上去更加 native(一共六篇)
- pip 在windows下的更新升级
- destoon中隐藏input框的值的设定
- uva725 - Division
- Qt 内存管理机制
- underscorejs-groupBy学习
- (4)基础概念介绍——导演、场景、层、精灵
- 摒弃以往的工作方法
- utunbu启动进入文本界