寒假第一天 水题 Steps
2013-01-20 09:23
246 查看
Steps
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.
with two integers: 0<= x <= y < 231
xto y.
Time Limit: 3000MS Memory limit: 65536K
题目描述
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 smallerthan 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 consists of a line containing n, the number of test cases. For each test case, a line followswith two integers: 0<= x <= y < 231
输出
For each test case, print a line giving the minimum number of steps to get fromxto y.
示例输入
3 45 48 45 49 45 50
示例输出
3 3 4
题目:从x到y 可以比前一步大一小一或者等于前一步的步长 但是第一步和最后一步都只能是1
求的是最短用的步数
思路:
从两边走第一次相差的距离两边同时减一 第二次两边的距离同时减2 第三次减三…… 当值出现负值的时候 就是最少路长~
#include<iostream> using namespace std; int main() { int s,e; int n; cin>>n; while(n--) { cin>>s>>e; int len=e-s; if(len==0) cout<<0<<endl; else if(len==1) cout<<1<<endl; else if(len==2) cout<<2<<endl; else { len-=2; int bushu=3; for(int i=2;;i++) { len-=i; if(len<=0) break; bushu++; len-=i; if(len<=0) break; bushu++; } cout<<bushu<<endl; } } return 0; }
相关文章推荐
- 寒假集训第一天——结构体
- 寒假水题之别救大兵瑞恩
- 2018年全国多校算法寒假训练营练习比赛(第三场)G大水题
- 寒假学习unity的第一天
- 1482. 奖学金 寒假第一天 自己写出来的第一道sicily题
- 寒假第一天1.12训练小结
- Codeforces Round #321 (Div. 2) A. Kefa and First Steps 水题
- 个人寒假作业项目《印象笔记》第一天
- codeforces水题100道 第十四题 Codeforces Round #321 (Div. 2) A. Kefa and First Steps (brute force)
- 寒假学习计划第一天
- 寒假第一题。。水题匈牙利切了1个小时。。坑爹
- 2016寒假联系——水题
- ACM 第一天水题
- 2013寒假SD高校ACM周赛3—Steps
- Steps 数论水题
- 假寒假第一天
- 大四寒假考试完之后第一天到MISON
- 这个寒假真正意义的开始----第一天学习OC。
- 13年山东省赛 The number of steps(概率dp水题)
- 寒假学习 第一天 (linux 高级编程)