您的位置:首页 > 其它

uva 10161 - Ant on a Chessboard

2014-01-02 21:46 375 查看
这题很简单,记得输出是x y不是(x,y),还wa了一次

#include<iostream>
#include<math.h>
using namespace std;
int main(){
int n;
while(cin>>n){
if(n==0)
break;
if(n==1){
cout<<"1 1"<<endl;
continue;
}
int nth=(int)sqrt((double)n);
nth=(n>nth*nth)?(nth+1):nth;
int flag=nth%2;
int temp=n-(nth-1)*(nth-1)-nth;
if(flag){

if(temp>=0)
cout<<nth-temp<<" "<<nth<<endl;
else
cout<<nth<<" "<<nth+temp<<endl;
}
else{
if(temp>=0)
cout<<nth<<" "<<nth-temp<<endl;
else
cout<<nth+temp<<" "<<nth<<endl;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: