【38.46%】【codeforces 615E】Hexagons
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Examples
Input
3
Output
-2 0
Input
7
Output
3 2
【题解】
规律题;
可以看到,每一圈的边数是等差数列;公差为6;
且边的长度和圈数有着对应的关系(除了>形的地方);
对于所给的n;
用二分搞出这是第几圈;
(an=6+(n-1)6,sn=(a1+an)n/2;->sn=3*n(n+1));
然后总数减去3*(key-1)*(key-1+1)key为n所在的圈数;
减掉之后的步数可以再模拟一下具体在哪个位置,找下规律就好;
坐标和圈数和剩余的步数mod圈数有关
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <string>
#define lson L,m,rt<<1
#define rson m+1,R,rt<<1|1
#define LL long long
using namespace std;
//const int MAXN = x;
const int dx[5] = {0,1,-1,0,0};
const int dy[5] = {0,0,0,-1,1};
const double pi = acos(-1.0);
LL n;
void input_LL(LL &r)
{
r = 0;
char t = getchar();
while (!isdigit(t) && t!='-') t = getchar();
LL sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
}
void input_int(int &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)&&t!='-') t = getchar();
int sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
}
int main()
{
//freopen("F:\\rush.txt","r",stdin);
input_LL(n);
if (n==0)
{
puts("0 0");
return 0;
}
LL l = 0,r = 1e9,m = 0;
while (l <= r)
{
LL mid = (l+r)>>1;
if (1LL*3*mid*(mid+1)<=n)
{
m = mid;
l = mid+1;
}
else
r = mid-1;
}
n-=3*m*(m+1);
if (n==0)
{
printf("%I64d 0\n",m*2);
return 0;
}
m++;
LL zc = n/m,yu = n % m;
//cout << zc << " "<<yu<<endl;
switch (zc)
{
case 0:
printf("%I64d %I64d\n",2*m-yu,2*yu);
break;
case 1:
printf("%I64d %I64d\n",m-2*yu,2*m);
break;
case 2:
printf("%I64d %I64d\n",-m-yu,2*m-yu*2);
break;
case 3:
printf("%I64d %I64d\n",-2*m+yu,-2*yu);
break;
case 4:
printf("%I64d %I64d\n",-m+2*yu,-2*m);
break;
case 5:
printf("%I64d %I64d\n",m+yu,-2*m+yu*2);
break;
case 6:
printf("%I64d %I64d\n",2*m,0);
break;
}
return 0;
}
【38.46%】【codeforces 615E】Hexagons的更多相关文章
- 【CodeForces 615E】Hexagons
找规律. #include <cstdio> #include <iostream> #include <algorithm> #include <cstri ...
- 【 BowWow and the Timetable CodeForces - 1204A 】【思维】
题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...
- 【38.02%】【codeforces 625B】War of the Corporations
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 【19.46%】【codeforces 551B】ZgukistringZ
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 46C】Hamsters and Tigers
[题目链接]:http://codeforces.com/problemset/problem/46/C [题意] 给你一个长度为n的01串; 让你把所有的0放在一起,把所有的1放在一起; (即0都是 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【搜索】【并查集】Codeforces 691D Swaps in Permutation
题目链接: http://codeforces.com/problemset/problem/691/D 题目大意: 给一个1到N的排列,M个操作(1<=N,M<=106),每个操作可以交 ...
- 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- 【链表】【模拟】Codeforces 706E Working routine
题目链接: http://codeforces.com/problemset/problem/706/E 题目大意: 给一个N*M的矩阵,Q个操作,每次把两个同样大小的子矩阵交换,子矩阵左上角坐标分别 ...
随机推荐
- docker中发布springboot
http://note.youdao.com/noteshare?id=81a603b1b33731aaef7b7755c70f33fb
- Python 极简教程(三)数据类型
每种语言都有各种数据类型.这就像在现实生活中,我们计数的时候需要用到数字,在表述金额.重量.距离等需要精确计数时用到小数,在日常交谈中要用文字,等等.在计算机语言中,为了表述不同的情况,也需要用到各种 ...
- 【Codeforces Round #301 (Div. 2) D】 Bad Luck Island
[链接] 我是链接,点我呀:) [题意] 剪刀.石头.布各有r,s,p个生活在同一个村子里. 它们两两之间相遇的几率都相同(相遇后就会按照划拳的规则判断输赢,输的人就死掉了). 问你最后只剩下剪刀,只 ...
- C++卷积神经网络实例:tiny_cnn代码具体解释(8)——partial_connected_layer层结构类分析(上)
在之前的博文中我们已经将顶层的网络结构都介绍完毕,包括卷积层.下採样层.全连接层,在这篇博文中主要有两个任务.一是总体贯通一下卷积神经网络在对图像进行卷积处理的整个流程,二是继续我们的类分析.这次须要 ...
- js闭包中的this(匿名函数中的this指向的是windows)
js闭包中的this(匿名函数中的this指向的是windows) 一.总结 1.普通函数中的this指向的是对象,匿名函数中的this指向的是windows,和全局变量一样 2.让匿名函数中的thi ...
- POJ 2752 Seek the Name, Seek the Fame (KMP)
传送门 http://poj.org/problem?id=2752 题目大意:求既是前缀又是后缀的前缀的可能的长度.. 同样是KMP,和 HDU 2594 Simpsons' Hidden Tale ...
- Snail—Hibernate各种异常
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXExNzkxNDIyMDE4/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- Declarative Widgets is a QML plugin that adds Qt Widgets support to QML
05.04.2018 Nathan Collins 8 comments FacebookTwitterGoogle+LinkedInEmail Declarative Widgets is a ...
- 如何使用google地图的api(整理)
如何使用google地图的api(整理) 一.总结 一句话总结:直接用script标签引google地图api即可. 1.如何使用google地图的api? 页面引用javascript文件<s ...
- 18、IIC总线驱动程序
i2c_s3c2410.c是内核自带dev层(adapt)驱动程序,知道怎么发收数据,不知道含义 在与i2c_s3c2410.c(在其probe函数中的s3c24xx_i2c_init函数会初始化ii ...