846 - Steps
来源:互联网 发布:知天下图片 编辑:程序博客网 时间:2024/06/04 16:46
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 toy? 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:0xy < 231. For each test case, print a line giving the minimum number of steps to get fromx to y.Sample Input
345 4845 4945 50
Sample Output
334
#include<stdio.h>int step(int p){int sum=0;sum=(1+p/2)*(p/2);if(p%2) sum+=p/2+1;return sum;}int main(void){int n,x,y,d;scanf("%d",&n);while(n--){scanf("%d%d",&x,&y);d=y-x;if(!d) puts("0");else {int j;for(j=0;j<y;j++)if(d<=step(j)){printf("%d\n",j); break;}}}return 0;}
- 846 - Steps
- 846 - Steps
- 846 - Steps
- 846 - Steps
- uva 846 Steps
- uva-846 steps
- uva 846 Steps
- UVA 846 - Steps
- uva 846 - Steps
- UVa 846 - Steps
- UVa 846 - Steps
- UVa 846-Steps
- UVa 846 - Steps
- UVA 846 Steps
- uva 846 - Steps
- UVa 846 Steps (数学)
- uva 846 Steps
- UVa 846 Steps
- void * 与 空指针NULL
- Maven学习二: Maven POM
- WebService概念及相关技术点
- UltraISO刻录光盘和制作可引导U盘教程
- Uva-10066-The Twin Towers
- 846 - Steps
- 通过逆向学习软件设计(2)
- [JAVA]集合框架简述,HashTable、ArrayList、Vector 记录
- 完善上一篇文章中的JTable中的操作
- B树、B-树、B+树、B*树
- Uva-531-Compromise
- 2013年6月29日
- 软件测试中过度设计的那些事儿
- C++ 排序函数 sort(),qsort()的用法