题意: 有t组测试数据。要求为最少步得到给出的整数n。步长要求为:起步和停止的步长为一,每次只能在上次的基础上增加一,减少一或者不变。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=700000;
#define LL long long
#define INF ((LL)1<<31)
LL a[N];
int main()
{
int cnt=2;
LL temp=1;
a[1]=1;a[0]=0;
while(1)
{
if(cnt%2==0) a[cnt]=a[cnt-1]+temp;
else
{
temp++;a[cnt]=a[cnt-1]+temp;
}
if(a[cnt]>INF) break;
cnt++;
}
int t;
scanf("%d",&t);
while(t--)
{
LL n,m,val;
scanf("%lld%lld",&n,&m);
val=m-n;
int pos=lower_bound(a,a+cnt,val)-a;
printf("%d\n",pos);
}
}