uva 10161 - Ant on a Chessboard

这题很简单,记得输出是x y不是(x,y),还wa了一次

 1 #include<iostream>
 2 #include<math.h>
 3 using namespace std;
 4 int main(){
 5     int n;
 6     while(cin>>n){
 7         if(n==0)
 8             break;
 9         if(n==1){
10             cout<<"1 1"<<endl;
11             continue;
12         }
13         int nth=(int)sqrt((double)n);
14         nth=(n>nth*nth)?(nth+1):nth;
15         int flag=nth%2;
16         int temp=n-(nth-1)*(nth-1)-nth;
17         if(flag){
18             
19             if(temp>=0)
20                 cout<<nth-temp<<" "<<nth<<endl;
21             else
22                 cout<<nth<<" "<<nth+temp<<endl;
23         }
24         else{
25             if(temp>=0)
26                 cout<<nth<<" "<<nth-temp<<endl;
27             else
28                 cout<<nth+temp<<" "<<nth<<endl;
29         }
30     }
31 }

 

posted on 2014-01-02 21:46  云在心  阅读(111)  评论(0)    收藏  举报

导航