CodeForces 615E Hexagons
来源:互联网 发布:化学发展史 知乎 编辑:程序博客网 时间:2024/05/18 19:37
题意:有个人会在图上的六边形那样走,问走了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
- CodeForces 615E Hexagons
- 【38.46%】【codeforces 615E】Hexagons
- Codeforces 615E Hexagons 【找规律】
- [Codeforces 615E] Hexagons (找规律)
- CF 615E Hexagons
- CodeForces 615E——Hexagons(二分,模拟)
- Codeforces 615E Hexagons (Round #338 (Div. 2) E题) 二分答案+找规律
- CodeForces Hexagons!
- CF 615 E Hexagons(找规律)
- Codeforces Round #338 (Div. 2) E. Hexagons 找规律
- Codeforces Round #338 (Div. 2) E. Hexagons(规律)
- COdeforces 630D Hexagons!
- CodeForces 630D-Hexagons!
- Codeforces 630D Hexagons!
- CodeForces 630D:Hexagons!【水】
- CodeForces 216A Tiling with Hexagons
- CodeForces 630 D. Hexagons!(水~)
- CodeForces - 630D Hexagons! (数学规律)
- web 前端,on的使用
- 八数码之 ①暴力BFS+哈希表版 ②双向BFS+输出最佳方案版
- MFC 多语言环境的实现
- Android 图片裁切框架 uCrop 的用法
- aspx 上传文件大小
- CodeForces 615E Hexagons
- c
- DOM操作为什么慢?
- netty5源码探索(一)----ByteBuf初探
- java mysql 数据类型对照
- 关于Tomcat 6的热部署和热加载
- Timeline Maker Pro 3.1.99 最新版 中文 汉化版 最好的 时间线 图表制作工具
- JAVA字符串占位符替换
- struts原理之xwork