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. Net判断一个对象是否为数值类型 z

    http://www.cnblogs.com/SkyD/p/4053461.html public static bool IsNumeric(this Type dataType) { if (da ...

  2. SQL查询数据库信息, 数据库表名, 数据库表信息

    SQL查询数据库信息, 数据库表名, 数据库表信息 ---------------------------------------------- -- 以下例子, 在sql_server 中可以直接运 ...

  3. 《深入理解C#》第3版 学习进度备忘

    学习资源:<深入理解C#>第3版 知识基础支持: <C# in a nutshell> O Reilly出版社,是一本从头介绍C#的优秀图书.<Essential C#5 ...

  4. 《C陷阱与缺陷》读书笔记

    1. 词法“陷阱” = 不同于 == , 可以通过if( 1 == a )来避免 & | 不同于 && || 词法分析中的“贪心法” 编译器将程序分解成符号的方法是,从左到右一 ...

  5. Java Web高性能开发(二)

    今日要闻: 性价比是个骗局: 对某个产品学上三五天个把月,然后就要花最少的钱买最多最好的东西占最大的便宜. 感谢万能的互联网,他顺利得手,顺便享受了智商上的无上满足以及居高临下的优越感--你们一千块买 ...

  6. Python:列表,元组

    一.列表 和字符串一样,列表也是序列类型,因此可以通过下标或者切片操作访问一个或者多个元素.但是,不一样的,列表是容器类型,是可以进行修改.更新的,即当我们进行修改列表元素,加入元素等操作的时候,是对 ...

  7. Flex之DataGrid和Tree控件的数据源XML格式

    1.flex的完整代码: <?xml version="1.0" encoding="utf-8"?> <s:Application xmln ...

  8. UIActivityViewController 自定义选项

    UIActivityViewController 自定义选项 重写 UIActivity 类 建议下载github上源码学习一下 https://github.com/samvermette/SVWe ...

  9. 各种边框样式。。本以为border不是这么用的。

    关于文本框样式□ 文本框样式 □ 显示虚线边框的文本框(IE5.5才可看到效果)  <INPUT style="border-width: 1px,1px,1px,1px;border ...

  10. LINQ标准查询操作符(三)——Aggregate、Average、Distinct、Except、Intersect、Union、Empty、DefaultIfEmpty、Range、Repeat

    七.聚合操作符 聚合函数将在序列上执行特定的计算,并返回单个值,如计算给定序列平均值.最大值等.共有7种LINQ聚合查询操作符:Aggregate.Average.Count.LongCount.Ma ...