CodeForces 615E Hexagons

题意:有个人会在图上的六边形那样走,问走了n步之后在哪里

思路:找规律…

#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long n;
    while(scanf("%lld",&n)!=EOF){
            if(n==0)return puts("0 0");
            n--;
    for(long long i=1;;i++)
    {
        long long cnt = i*6;
        if(n>=cnt)n-=cnt;
        else
        {
            if(n<i)
            {
                printf("%lld %lld\n",i*2-1-n,2+2*n);
                break;
            }
            n-=i;
            if(n<i)
            {
                printf("%lld %lld\n",i-2-2*n,2*i);
                break;
            }
            n-=i;
            if(n<i)
            {
                printf("%lld %lld\n",-1-i-n,2*i-2*n-2);
                break;
            }
            n-=i;
            if(n<i)
            {
                printf("%lld %lld\n",-2*i+1+n,-2+(-2)*n);
                break;
            }
            n-=i;
            if(n<i)
            {
                printf("%lld %lld\n",2-i+2*n,-2*i);
                break;
            }
            n-=i;
            printf("%lld %lld\n",i+n+1,2-2*i+2*n);
            break;

        }
    }
    }
    return 0;
}

Description
Ayrat is looking for the perfect code. He decided to start his search from an infinite field tiled by hexagons. For convenience the coordinate system is introduced, take a look at the picture to see how the coordinates of hexagon are defined:

Ayrat is searching through the field. He started at point (0, 0) and is moving along the spiral (see second picture). Sometimes he forgets where he is now. Help Ayrat determine his location after n moves.

Input
The only line of the input contains integer n (0 ≤ n ≤ 1018) — the number of Ayrat’s moves.

Output
Print two integers x and y — current coordinates of Ayrat coordinates.

Sample Input
Input
3
Output
-2 0
Input
7
Output
3 2

你可能感兴趣的:(CodeForces 615E Hexagons)