E. Hexagons

题目连接:

http://codeforces.com/contest/615/problem/E

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

3

Sample Output

-2 0

Hint

题意

有一个人会在坐标上按照六边形那样走,会一直走下去

问你走了n步之后,这个人会在哪儿。

题解:

就不停的讨论讨论……

首先我们先确定他在第几个环上,我们将环切成6份,然后再看他在哪一份上

然后再计算就好了……

不停讨论讨论

代码

#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;
}

Codeforces Round #338 (Div. 2) E. Hexagons 讨论讨论的更多相关文章

  1. Codeforces Round #338 (Div. 2) D. Multipliers 数论

    D. Multipliers 题目连接: http://codeforces.com/contest/615/problem/D Description Ayrat has number n, rep ...

  2. Codeforces Round #338 (Div. 2) C. Running Track dp

    C. Running Track 题目连接: http://www.codeforces.com/contest/615/problem/C Description A boy named Ayrat ...

  3. Codeforces Round #338 (Div. 2) B. Longtail Hedgehog dp

    B. Longtail Hedgehog 题目连接: http://www.codeforces.com/contest/615/problem/B Description This Christma ...

  4. Codeforces Round #338 (Div. 2) A. Bulbs 水题

    A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...

  5. Codeforces Round #338 (Div. 2)

    水 A- Bulbs #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1 ...

  6. Codeforces Round #338 (Div. 2) D 数学

    D. Multipliers time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  7. Codeforces Round #338 (Div. 2) B dp

    B. Longtail Hedgehog time limit per test 3 seconds memory limit per test 256 megabytes input standar ...

  8. Codeforces Round #338 (Div. 2) B. Longtail Hedgehog 记忆化搜索/树DP

    B. Longtail Hedgehog   This Christmas Santa gave Masha a magic picture and a pencil. The picture con ...

  9. DFS/BFS Codeforces Round #301 (Div. 2) C. Ice Cave

    题目传送门 /* 题意:告诉起点终点,踩一次, '.'变成'X',再踩一次,冰块破碎,问是否能使终点冰破碎 DFS:如题解所说,分三种情况:1. 如果两点重合,只要往外走一步再走回来就行了:2. 若两 ...

随机推荐

  1. jquery选择器的使用

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  2. 30+简约时尚的Macbook贴花

    当Macbooks Pro电脑在他们的设计之下仍然漂亮.独一无二时,我想说,他们已经成为相当的主流了.有时候如果你回忆过去的很美好的日子,当人们偷偷欣赏你的技术装备 的时候,大概是为你的外表增加亮点的 ...

  3. JQuery Mobile移动Web应用开发(1): UI开发工具RID介绍

    工欲善其事,必先利其器. UI工具可以提高我们开发界面的效率,下面对几款工具做个对比: 1. Codiqa,在JQuery Mobile主页能看到这款工具,看到网上这么多人吹捧这个工具,不过是收费的. ...

  4. openstack 基本配置

  5. 关于python requests包新版本设置代理的问题

    在更新了requests包之后,发现我电脑上的charles工具无法再成功抓取到数据包.百度了半年都没有找到原因. 然后 我使用了 google 查到了 charles的最新的文档发现.需要设置代理, ...

  6. 【125】固定IP的电脑配置无线路由

    标题所提到的情况即为有些电脑是用静态IP上网的,与普通的宽带连接稍微有些不同,例如我的电脑的静态IP设置是这样的: 只有按照上面的设置才可以正常上网,因此在配置无线路由器的时候也要用到上面的内容,废话 ...

  7. HNC-全局联想脉络

    全局联想脉络—语义块 和句类 一个语义块包含 核心部分 和说明部分. 语义块分为: 主语义块:有 4 种:特征E.作用者A.对象B.内容C 辅语义块:有 7 种:条件.手段.工具.途径.参照.因.果. ...

  8. hdoj 5344 MZL's xor

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5344 #include<stdio.h> #include<cstring> ...

  9. springMVC+JAP整合彻底摆脱persistence.xml配置文件

    <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...

  10. openmp 并行求完数

    // GetWanShu.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include "omp.h" #inclu ...