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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值