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. 工具栏ToolStrip能触发焦点控件的Leave、Validating、DataError等事件以验证数据 z

    public class ToolStripEx : ToolStrip { protected override void OnClick(EventArgs e) { base.OnClick(e ...

  2. Boost下载安装编译配置使用指南

    转载:http://www.cppblog.com/jerryma/archive/2011/10/17/158554.html --更新于2011/7/19,目前我已对boost的安装和使用有了新的 ...

  3. Java中实现异常处理的基础知识

    Java中实现异常处理的基础知识 异常 (Exception):发生于程序执行期间,表明出现了一个非法的运行状况.许多JDK中的方法在检测到非法情况时,都会抛出一个异常对象. 例如:数组越界和被0除. ...

  4. 黑马程序员——OC的内存管理学习小结

    内存管理在Objective-C中的重要性就像指针在C语言中的重要程序一样. 虽然作为一门高级语言,但OC却没有内存回收机制.这就需要开发者来对动态内存进行管理.OC中内存管理的范围是:任何继承了NS ...

  5. C++设计模式——单例模式

    问题描述 现在,不管开发一个多大的系统(至少我现在的部门是这样的),都会带一个日志功能:在实际开发过程中,会专门有一个日志模块,负责写日志,由于在系统的任何地方,我们都有可能要调用日志模块中的函数,进 ...

  6. 45个有新意的Photoshop教程和技巧

    图形制作者和网页设计师已经准备好迎接新的Adobe Photoshop 教程了.在大家喜欢背后有许多它的理由,诸如Adobe Photoshop很容易操作,学习起来十分简单,但最重要的一点是这款软件能 ...

  7. linux安装lua相关编译报错

    1.报之类的错误 /usr/lib/libreadline.so: undefined reference to `PC' /usr/lib/libreadline.so: undefined ref ...

  8. linux 从命令行自动识别文件并将其打开的命令

    若是shell是 zsh,则可: 使用 alias -s 定义后缀别名 (zsh) % alias -s pl=perl % script.pl perl script.pl % alias -s p ...

  9. 第二百零三天 how can I 坚持

    空虚的有点害怕. 日复一日. 今天做了什么?下班看了个搞笑段子. 上班和刘松聊了一下午,东扯西扯的. 下班玩了两局dota. 想租车去出去玩玩,确实没有什么想去的地方了. 莫巧菲. 哎,未来好可怕啊. ...

  10. SpringMVC处理Date类型的成员变量方法

    原文链接:http://www.tuicool.com/articles/aYfaqa 在使用 SpringMVC 的时候,我们可能需要将一个对象从 View 传递给 Controller .而当这个 ...