当前位置:网站首页>[51nod] 3395 n-bit gray code

[51nod] 3395 n-bit gray code

2022-06-24 02:49:00 SSL_ GYX

n Bit code

Link


 Insert picture description here

Their thinking

If a digit is equal to the previous digit , Then this one is 1 1 1 , It is 0 0 0 , Can be done with or .

code

#include<iostream>
#include<cstdio>
#define int long long
using namespace std;

int n;

void output(int x)
{
    
	int a[20],tot=0;
	while(x) a[++tot]=x%2,x>>=1;
	for(int i=n;i>tot;i--) printf("0");
	while(tot) printf("%lld",a[tot--]);
	printf("\n");	
}

signed main()
{
    
	cin>>n;
	for(int i=0;i<(1<<n);i++)
		output(i^(i>>1));
}
原网站

版权声明
本文为[SSL_ GYX]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211645221802.html