Codeforces Round #338 (Div. 2) E. Hexagons 讨论讨论
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 讨论讨论的更多相关文章
- Codeforces Round #338 (Div. 2) D. Multipliers 数论
D. Multipliers 题目连接: http://codeforces.com/contest/615/problem/D Description Ayrat has number n, rep ...
- 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 ...
- Codeforces Round #338 (Div. 2) B. Longtail Hedgehog dp
B. Longtail Hedgehog 题目连接: http://www.codeforces.com/contest/615/problem/B Description This Christma ...
- Codeforces Round #338 (Div. 2) A. Bulbs 水题
A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...
- Codeforces Round #338 (Div. 2)
水 A- Bulbs #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1 ...
- Codeforces Round #338 (Div. 2) D 数学
D. Multipliers time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #338 (Div. 2) B dp
B. Longtail Hedgehog time limit per test 3 seconds memory limit per test 256 megabytes input standar ...
- 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 ...
- DFS/BFS Codeforces Round #301 (Div. 2) C. Ice Cave
题目传送门 /* 题意:告诉起点终点,踩一次, '.'变成'X',再踩一次,冰块破碎,问是否能使终点冰破碎 DFS:如题解所说,分三种情况:1. 如果两点重合,只要往外走一步再走回来就行了:2. 若两 ...
随机推荐
- mongo 安装
mongo 安装: 1.按照 https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/ 安装 2.安装成功后创建用户 d ...
- 【转】Win 7 下源码运行OpenERP7.0
原文地址:Win 7 下源码运行OpenERP7.0 安装Python2.7 下载地址:http://www.python.org/getit/注:OpenERP7.0支持的Python版本最高为2. ...
- linux中ls命令详解 (转)
-a -- 全部(all).列举目录中的全部文件,包括隐藏文件(.filename).位于这个列表的起首处的 .. 和 . 依次是指父目录和你的当前目录. -l -- 长(long).列举目 ...
- Solaris系统管理(一)
最近需要将一个项目从Linux平台迁移到Solaris,对Solaris进行了一点研究,总结如下. 一句话介绍: Solaris 是Sun Microsystems研发的计算机操作系统.它被认为是UN ...
- Windows上的的神技能,你知道几个?(Windows技巧大全,已更新)
不用借助任何第三方软件,其实Windows也大有可为——比你目前了解得至少要多得多,强大技能快来get起来! 1.文件隐藏谁的电脑里没点小秘密?东藏西藏到最后自己都找不到了有木有?今天教大家个隐藏文件 ...
- 关于python中字典的一些总结
1. 获取字典中的值,但是无异常 当在字典中取值的时候,可以使用如下两种方式: >>> d = {'name':'kel'} >>> d {'name': 'kel ...
- 【LeetCode】83 - Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...
- Android中的颜色值RGB对照表表
Android中颜色值是通过红(Red).绿(Green).蓝 (Blue)三原色,以及一个透明度(Alpha)值来表示的,颜色值总是以井号(#)开头,接下来就是Alpha-Red-Green-Blu ...
- Vi的基本使用方法
转载自http://linux.chinaunix.net/doc/office/2005-01-24/898.shtml vi编辑器是所有Unix及Linux系统下标准的编辑器,它的强大不逊色于任何 ...
- [cocos2d-js]长按按钮事件
定义两个全局变量 var bLeftButtonClick = false; var bRightButtonClick = false; var MainLayer = cc.Layer.exten ...