UVa_OJ 10161 棋盘上的蚂蚁
2016-10-11 11:21
375 查看
这道题比较简单,AC代码如下:
#include<stdio.h>
#include<math.h>
int main(){
#ifdef LOCAL
freopen("10161_input.txt","r",stdin);
freopen("10161_output.txt","w",stdout);
#endif
int N,x,y,srt,tmp;
while(scanf("%d",&N)==1&&N!=0){
srt=(int)sqrt((double)N);
tmp=N-srt*srt;
if(srt%2==0){
x=srt;
if(tmp==0)
y=1;
else if(tmp<=(srt+1)){
x+=1;
y=tmp;
}
else{
y=srt+1;
x-=(tmp-(srt+2));
}
}
else{
y=srt;
if(tmp==0)
x=1;
else if(tmp<=(srt+1)){
y+=1;
x=tmp;
}
else{
x=srt+1;
y-=(tmp-(srt+2));
}
}
printf("%d %d\n",x,y);
}
return 0;
}
#include<stdio.h>
#include<math.h>
int main(){
#ifdef LOCAL
freopen("10161_input.txt","r",stdin);
freopen("10161_output.txt","w",stdout);
#endif
int N,x,y,srt,tmp;
while(scanf("%d",&N)==1&&N!=0){
srt=(int)sqrt((double)N);
tmp=N-srt*srt;
if(srt%2==0){
x=srt;
if(tmp==0)
y=1;
else if(tmp<=(srt+1)){
x+=1;
y=tmp;
}
else{
y=srt+1;
x-=(tmp-(srt+2));
}
}
else{
y=srt;
if(tmp==0)
x=1;
else if(tmp<=(srt+1)){
y+=1;
x=tmp;
}
else{
x=srt+1;
y-=(tmp-(srt+2));
}
}
printf("%d %d\n",x,y);
}
return 0;
}
相关文章推荐
- UVa 10161 棋盘上的蚂蚁
- uva 10161-棋盘上的蚂蚁
- UVa 10161 棋盘上的蚂蚁
- UVA 10161 棋盘上的蚂蚁
- UVa Problem 10161 Ant on a Chessboard (棋盘上的蚂蚁)
- 九度 oj 题目1159:坠落的蚂蚁
- uva 10161 Ant on a Chessboard
- UVa 10161 - Ant on a Chessboard
- 100 - The 3n + 1 problem Form UVa OJ
- UVA 10161 --- Problem A.Ant on a Chessboard 找规律
- uva oj 10300
- uvaoj401
- UVA 10161 (暑假-数学-B - Ant on a Chessboard)
- UVA - 10161 Ant on a Chessboard
- uva 10161 - Ant on a Chessboard
- zzuoj1225 棋盘游戏 最简单的博弈——巴什博弈(bash game)
- Uva 10881蚂蚁
- UVA 10161 - Ant on a Chessboard(数学)
- UVa OJ 10082-WERTYU
- UVa OJ 10106-Product