Advertisement
LucasLima

Ant on a Chessboard - UVa 10161

Oct 25th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cmath>
  3. #include <utility>
  4.  
  5. using namespace std;
  6.  
  7. typedef pair<int,int> ii;
  8. ii calc(int n) {
  9.     int dim = (int)ceil(sqrt((double)n));
  10.     int aux = (dim-1)*(dim-1)+dim;
  11.     if(n == aux) {
  12.         return ii(dim,dim);
  13.     } else if(n < aux) {
  14.         if(dim&1) {
  15.             return ii(dim,n-(dim-1)*(dim-1));
  16.         } else {
  17.             return ii(n-(dim-1)*(dim-1),dim);
  18.         }
  19.     } else {
  20.         if(dim&1) {
  21.             return ii(dim*dim-n+1,dim);
  22.         } else {
  23.             return ii(dim,dim*dim-n+1);
  24.         }
  25.     }
  26. }
  27.  
  28. int main () {
  29.     int n;
  30.     while(scanf("%d",&n) && n) {
  31.         ii ret = calc(n);
  32.         printf("%d %d\n",ret.first,ret.second);
  33.     }
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement