タイトル
図に示すように便宜上無限ハニカムラビリンスが、今迷路の座標に組み込まれ、六方格子のそれぞれを表してあります。
この迷路愛Ruite通りで、彼は以下の通り、この迷路で走行路に合わせて、位置(0,0)で始まりました。
nは、すぐそばの後、彼はどのような位置を知りたいと思いました。
考え
取るステップ1-6 1層2層のステップ7-18、バイナリサーチ層の数、場合6 6歩行エッジの最終層
コード
#include<bits/stdc++.h>
#define ll long long
#define db double
using namespace std;
ll n;
int main(){
cin>>n;
if(n==0){
cout<<"0 0\n";
return 0;
}
ll l=1,r=1e9,mid,lev;
while(l<=r){
mid=(l+r)>>1;
if(3*mid*(mid-1)<n){
l=mid+1;
lev=mid;
}
else r=mid-1;
}
//cout<<lev<<endl;
ll cx=-1+2*lev,cy=2;
n-=3*lev*(lev-1);n--;
if(n<=lev-1){
cx-=n,cy+=2*n;
cout<<cx<<' '<<cy<<endl;
return 0;
}
n-=(lev-1);
cx-=(lev-1),cy+=2*(lev-1);
if(n<=lev){
cx-=2*n;
cout<<cx<<' '<<cy<<endl;
return 0;
}
n-=lev;
cx-=lev*2;
if(n<=lev){
cx-=n,cy-=2*n;
cout<<cx<<' '<<cy<<endl;
return 0;
}
n-=lev;
cx-=lev,cy-=2*lev;
if(n<=lev){
cx+=n,cy-=2*n;
cout<<cx<<' '<<cy<<endl;
return 0;
}
n-=lev;
cx+=lev,cy-=2*lev;
if(n<=lev){
cx+=2*n;
cout<<cx<<' '<<cy<<endl;
return 0;
}
n-=lev;
cx+=2*lev;
if(n<=lev){
cx+=n,cy+=2*n;
cout<<cx<<' '<<cy<<endl;
return 0;
}
n-=lev;
cx+=lev,cy+=2*lev;
return 0;
}