当前位置:网站首页>[51nod p3395] n-bit gray code [bit operation]
[51nod p3395] n-bit gray code [bit operation]
2022-06-13 09:35:00 【Ayane.】
analysis :
n n n Bit gray code at most 2 n 2^n 2n individual
For a binary number x x x if x x x Of the i i i Place and number i + 1 i+1 i+1 Same bit Then the number of gray code i + 1 i+1 i+1 Position as 0 0 0 Otherwise 1 1 1
Obviously This is XOR
CODE:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define reg register
using namespace std;
typedef long long ll;
int n,k;
int main(){
scanf("%d",&k);
n=1<<k;
for(int i=0;i<n;i++)
{
for(int j=k;j>=1;j--)
printf("%d",(i>>(j-1)&1)^(i>>j&1));
printf("\n");
}
return 0;
}
边栏推荐
- 批量讀取文件夾下的全部語音文件
- LeetCode 5270. 网格中的最小路径代价(动态规划)
- Musk's "meta universe" dream
- 202012 CCF test questions
- LeetCode 5259. Calculate the total tax payable
- [most comprehensive and detailed explanation] detailed explanation of knapsack problem
- Routing - static routing
- Solov2 nanny level tutorial (including environment configuration, training your own data set, code logic analysis, etc...) Updating ing
- acwing 788. Number of pairs in reverse order
- (bfs+GOOD) acwing 845. Eight digit
猜你喜欢

Yolov5 face learning notes

Jenkins接入Openldap用戶認證

C language: deep understanding of pointers and arrays

阿里高级专家剖析 | Protocol的标准设计

Acwing785. quick sort (sort+ quick sort + merge sort)

Cisco, Huawei network equipment

C language: five custom types

acwing 790. The third root of a number (dichotomy)

(topological sorting +bfs) acwing 848 Topological sequence of digraph

Figure: concept of figure
随机推荐
The turtle library displays the system time
LeetCode 202. 快乐数
MOOC week 8 programming exercise 1
QML(06)——qml. Add a new folder under QRC
Alibaba senior experts analyze the standard design of protocol
LeetCode 72. Edit distance
Sequential representation of linear tables
(bfs+GOOD) acwing 845. Eight digit
[ssl1280] full arrangement
Exercise 7-7 string replacement (15 points)
C # introductory series (XIII) -- getting to know the structure for the first time
LeetCode 5289. 公平分发饼干(DFS)
Classes and objects -- object model and this pointer
删除软链接
拜登:希望尽快签署两党枪支安全改革法案
LeetCode 5270. Minimum path cost in grid (dynamic programming)
C language: dynamic memory management
Storage mode of drawings
Routing - static routing
LeetCode 343. integer partition

