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) i--;
  18         int level = (i-1)/2+1;
  19         int offset = n - 3*(level-1)*level-2;
  20         switch (offset / level) {
  21         case 0:
  22             cout << level-1 - offset % level<< ' ' << 1 + offset % level << endl;
  23             break;
  24         case 1:
  25             cout << -1 - offset % level <<' ' << level << endl;
  26             break;
  27         case 2:
  28             cout << - level << ' ' << level - 1 - offset % level << endl;
  29             break;
  30         case 3:
  31             cout << 1 - level + offset % level << ' ' << -1 - offset % level << endl;
  32             break;
  33         case 4:
  34             cout << 1 + offset % level << ' ' << - level << endl;
  35             break;
  36         case 5:
  37             cout << level << ' ' << 1 - level + offset % level << endl;
  38             break;
  39         }
  40     }
  41     return 0;
  42 }
ch3n2k.com | Copyright (c) 2004-2020 czk.