zrq495
www.zrq495.com

对角线上的数字满足     an = n * (n - 1) + 1;

再通过列或者行的奇偶性以及与对角线数字的关系得到坐标。

代码如下:

 1 #include<iostream>
 2 #include<cmath>
 3 
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     int n;
 9     while(cin >> n, n)
10     {
11         int c=(int)ceil(sqrt(n));
12         int a=c*(c-1)+1;
13         if (c & 1)
14         {
15             if (n>=a)
16                 cout << (c-(n-a)) << " " << c << endl;
17             else
18                 cout << c << " " << c-(a-n) << endl;
19         }
20         else
21         {
22             if (n>=a)
23                 cout << c << " " << (c-(n-a)) << endl;
24             else
25                 cout << (c-(a-n)) << " " << c << endl;
26         }
27     }
28     return 0;
29 }
posted on 2012-07-24 14:15  zrq495  阅读(351)  评论(0编辑  收藏  举报