Steps
| 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: 0Sample Input
3 45 48 45 49 45 50
Sample Output
3 3 4
__________________________________-
代码:
#include<stdio.h>
int main(){
//freopen("file.in", "r", stdin);
int T = 0;
scanf_s("%d", &T);
while (T--){
int x, y;
scanf_s("%d%d", &x, &y);
int dis = y - x;
int d = 0, count = 0;
while (dis>0){
dis -= ++d;
count++;
if (dis>0){
dis -= d;
count++;
}
}
printf("%d\n", count);
}
return 0;
}

本文探讨了在给定条件下,从一个位置到另一个位置所需的最少步骤数,涉及步长变化和路径优化。
894

被折叠的 条评论
为什么被折叠?



