poj2590

简单题,注意判断0

View Code
   
     
#include < iostream >
#include
< cstdio >
#include
< cstdlib >
#include
< cstring >
#include
< cmath >
using namespace std;

int main()
{
// freopen("t.txt", "r", stdin);
int t;
scanf(
" %d " , & t);
while (t -- )
{
int a, b;
scanf(
" %d%d " , & a, & b);
int c = abs(b - a);
if (c == 0 )
{
printf(
" 0\n " );
continue ;
}
int x = ceil(sqrt(c));
while (x * x >= c)
x
-- ;
int y = c - x * x;
if (y <= x)
printf(
" %d\n " , x * 2 );
else
printf(
" %d\n " , x * 2 + 1 );
}
return 0 ;
}

你可能感兴趣的:(poj)