1 #include<iostream> 2 #include<algorithm> 3 #define MAXN 1000000 4 using namespace std; 5 6 unsigned a[MAXN]; 7 8 int main() 9 { 10 //freopen("acm.acm","r",stdin); 11 int i; 12 int num = 1; 13 int time = 0; 14 int x; 15 int y; 16 a[0] = 0; 17 for(i = 1; i < MAXN; ++ i) 18 { 19 a[i] = a[i-1] + num; 20 ++ time; 21 if(time == 2) 22 { 23 ++ num; 24 time = 0; 25 } 26 } 27 cin>>num; 28 while(num --) 29 { 30 cin>>x>>y; 31 cout<<lower_bound(a,a+MAXN,abs(y-x))-a<<endl; 32 } 33 }
时间: 2024-09-21 15:33:07