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;
}

posted @ 2011-05-17 12:56  金海峰  阅读(161)  评论(0编辑  收藏  举报