您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息