UVA 10161-Ant on a Chessboard
来源:互联网 发布:闪凌网络是真的吗 编辑:程序博客网 时间:2024/06/05 06:34
这道题是一道有规律的数学题,容易根据图推出每一圈的数字的规律,对于给定输入的N,取√N的整数部分k;如果k^2的平方等于N的话,要么(1,N*N),要么(N*N,1),否则,k^2的肯定小于N,所以,k^2<N<(k+1)^2。至于是第几个那要控制好。然后在根据图判断应该在第几个的位置,但是要注意奇偶正好是反过来的;
code:
#include <stdio.h>
#include <math.h>
int main()
{
int n,s,k;
int x,y;
while(scanf(\"%d\",&n)==1,n)
{
k=(int)sqrt(n);
s=k;
k*=k;
if(n==k) x=1,y=s;
else
{
s++;
n-=k;
if(n<=s)
{
x=s;
y=n;
}
else if(n>s)
{
x=2*s-n;
y=s;
}
}
if(s%2!=0)
printf(\"%d %d\\n\",x,y);
else
printf(\"%d %d\\n\",y,x);
}
return 0;
}
- uva 10161 Ant on a Chessboard
- UVA 10161 - Ant on a Chessboard
- uva 10161 - Ant on a Chessboard
- UVa 10161 - Ant on a Chessboard
- UVA 10161-Ant on a Chessboard
- uva 10161 - Ant on a Chessboard
- UVa 10161 - Ant on a Chessboard
- UVA 10161 Ant on a Chessboard
- uva 10161 - Ant on a Chessboard
- UVa 10161: Ant on a Chessboard
- uva 10161 Ant on a Chessboard
- UVA 10161 Ant on a Chessboard
- uva 10161 - Ant on a Chessboard
- UVa 10161 - Ant on a Chessboard
- UVA - 10161 - Ant on a Chessboard
- uva--10161--Ant on a Chessboard
- UVa 10161 Ant on a Chessboard
- UVa 10161 - Ant on a Chessboard
- UVA 11069 - A Graph Problem
- UVA 10943 - How do you add
- UVA 10491-Cows and Cars
- UVA 10706 - Number Sequence
- UVA 10375 - Choose and divide
- UVA 10161-Ant on a Chessboard
- UVA 10177 - (234)-D SqrRectsCubesBoxes
- UVA 10182 - Bee Maja
- UVA 10195 - The Knights Of The Round Table
- UVA 10209 - Is This Integration
- UVA 10215 - The LargestSmallest Box ...
- UVA 10310 - Dog and Gopher
- UVA 439 - Knight Moves
- POJ 1979 - Red and Black