无语了,还以为是神题。没敢看。SB了,写二分时手残少写个= o(╯□╰)o
题意:一个人沿着图中走正六边形,问n步后在哪个坐标。
思路:分类讨论。。。。。。第i圈走6*i步,每圈分6段,一步步找就KO了。
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <string>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define MAXN (100000+10)
#define MAXM (200000+10)
#define Ri(a) scanf("%d", &a)
#define Rl(a) scanf("%lld", &a)
#define Rf(a) scanf("%lf", &a)
#define Rs(a) scanf("%s", a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%.2lf\n", (a))
#define Pl(a) printf("%lld\n", (a))
#define Ps(a) printf("%s\n", (a))
#define W(a) while(a--)
#define CLR(a, b) memset(a, (b), sizeof(a))
#define MOD 10007
#define LL long long
#define lson o<<1, l, mid
#define rson o<<1|1, mid+1, r
#define ll o<<1
#define rr o<<1|1
#define PI acos(-1.0)
#define first fi
#define second se
using namespace std;
LL Find(LL l, LL r, LL n)
{
LL ans = 0;
while(r >= l)
{
LL mid = (l + r) >> 1;
if(3 * (mid + 1) * mid <= n)
{
ans = mid;
l = mid+1;
}
else
r = mid-1;
}
return ans;
}
int main()
{
LL n; Rl(n);
LL x, y;
if(n == 0)
x = 0, y = 0;
else
{
LL r = 1000000000;
LL t = Find(1, r, n); //Pl(t);
LL yu = n - 3 * t * (t + 1);
t++;
if(yu == 0)
x = 2*(t-1), y = 0;
else
{
LL tt = yu / t;
yu = yu - tt * t;
//Pl(tt);
if(tt == 0)
x = 2*t - yu, y = 2*yu;
else if(tt == 1)
x = t - yu*2, y = 2*t;
else if(tt == 2)
x = -t - yu, y = 2*t - 2*yu;
else if(tt == 3)
x = -2*t + yu, y = -2*yu;
else if(tt == 4)
x = -t + 2*yu, y = -2*t;
else if(tt == 5)
x = t + yu, y = -2*t + 2*yu;
else
x = 2*t, y = 0;
}
}
printf("%lld %lld\n", x, y);
return 0;
}