UVA 10161 - Ant on a Chessboard

#include<cstdio>
#include<cmath>

int n ,s ,a;
int x, y;
int main()
{
while( scanf( "%d", &n) == 1)
{
if( n == 0) break;
a = ( int )sqrt( n);
s = a;
a *= a;
if( n == a)
x = 1, y = s;
else {
s ++;
n -= a;
if( n <= s) {
x = s;
y = n;
}
else if( n > s)
{
x = ( s * 2) - n;
y = s;
}
}
if( s % 2)
printf( "%d %d\n", x, y);
else
printf( "%d %d\n", y, x);
}
return 0;
}

找到坐标...好难推啊

你可能感兴趣的:(ant)