UVA - 846 Steps
题目大意:从A数字 到B数字 需要加几次 第一次加和最后一次加只能加1 中间的 只能比上一次多加1 或者少加1 或者相等
解题思路:因为最后一部和第一步是1 所以这个走法 基本上数成对称形式的 需要注意的数 最中间的1个或者两步数是可以为非对称的
#include <cstdio>
#include <cstring>
int main() {
int N;
scanf("%d", &N);
while (N--) {
int a, b;
int t = 0;
scanf("%d%d", &a, &b);
int s = b - a;
for (int i = 1; s != 0;) {
if ( s - 3*i + 1 >= 0) {
s = s - 2*i;
i++;
t = t + 2;
}
else {
if ( s == i ) {
s = s - i;
t++;
}
else {
if ( (s == 2*i || s == 2*i -1)&& i != 1) {
s = 0;
t = t + 2;
}
else i = i -1;
}
}
}
printf("%d\n", t);
}
}