比赛 |
EYOI常规赛 4th |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
格雷码 |
最终得分 |
100 |
用户昵称 |
遥时_彼方 |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2022-05-27 19:27:59 |
显示代码纯文本
#include<bits/stdc++.h>
#define rep(x,y,z) for(int x=y;x<=z;x++)
#define drep(x,y,z) for(int x=y;x>=z;x--)
#define ull unsigned long long
#define ll long long
using namespace std;
inline int read()
{
int x=0;bool flag=1;char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-')flag=0;ch=getchar();}
while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
if(flag) return x;
return ~(x-1);
}
inline void write(int x)
{
if(x<0) {x=~(x-1);putchar('-');}
if(x>9) write(x/10);
putchar(x%10+'0');
}
//////////////////
const ull one=1;
int nc;
ull kc;
ull p[65];
char ans[101];
inline void get_P(){drep(i,64,1) p[i-1]=p[i]/2;}
void solve(int dep,ull x,int y)
{
// cout<<dep<<" "<<x<<" "<<y<<" "<<p[dep-1]<<endl;
if(dep==0) return;
if(y)
{
if(x<=p[dep-1])
{
ans[nc-dep+1]='0';
solve(dep-1,x,1);
}
else
{
ans[nc-dep+1]='1';
solve(dep-1,x-p[dep-1]-1,0);
}
}
else
{
if(x<=p[dep-1])
{
ans[nc-dep+1]='1';
solve(dep-1,x,1);
}
else
{
ans[nc-dep+1]='0';
solve(dep-1,x-p[dep-1]-1,0);
}
}
}
int main()
{
freopen("2019code.in","r",stdin);
freopen("2019code.out","w",stdout);
nc=read();
cin>>kc;
p[64]=1;
p[64]-=2;
// cout<<p[64];
get_P();
solve(nc,kc,1);
rep(i,1,nc) cout<<ans[i];
cout<<endl;
return 0;
}
//2^64-1=18446744073709551615