Bee Maja
http://acm.zju.edu.cn/show_problem.php?pid=1954
1 /*Written by czk*/
2 #include <iostream>
3 #include <algorithm>
4 #include <string>
5 #include <cmath>
6 using namespace std;
7
8 int main() {
9 int n;
10 while (cin >> n ) {
11 if (n==1) {
12 cout << "0 0" << endl;
13 continue;
14 }
15 double r = sqrt((double)(4*n-5)/3);
16 int i = floor(r);
17 if (i%2==0)
18 i--;
19 int level = (i-1)/2+1;
20 int offset = n - 3*(level-1)*level-2;
21 switch (offset / level) {
22 case 0:
23 cout << level-1 - offset % level<< ' ' << 1 + offset % level << endl;
24 break;
25 case 1:
26 cout << -1 - offset % level <<' ' << level << endl;
27 break;
28 case 2:
29 cout << - level << ' ' << level - 1 - offset % level << endl;
30 break;
31 case 3:
32 cout << 1 - level + offset % level << ' ' << -1 - offset % level << endl;
33 break;
34 case 4:
35 cout << 1 + offset % level << ' ' << - level << endl;
36 break;
37 case 5:
38 cout << level << ' ' << 1 - level + offset % level << endl;
39 break;
40 }
41 }
42 }