当前位置:网站首页>[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;
}
边栏推荐
- Class template
- turtle库显示系统时间
- Resolve importerror:lib*** so--cannot open shared object file: No such... (pycharm/clion reports an error but the shell does not)
- (bfs) acwing 847. Hierarchy of points in the graph
- Yolov5 face learning notes
- 拜登:希望尽快签署两党枪支安全改革法案
- 攻防世界PWN play 条件竞争漏洞的利用
- C language: sanziqi
- C language: timer principle
- Jenkins接入Openldap用戶認證
猜你喜欢

(dfs+ pruning + checkerboard problem +dood) acwing 843 N-queen problem

Jenkins access openldap user authentication

C language: dynamic memory management

Exploitation of competitive loopholes in attacking and defending world PWN play conditions

Tree and binary tree: basic operation and implementation of binary tree

C language: recursive function to realize Hanoi Tower

C language: minesweeping
![[implementation of depth first search]](/img/10/4f150e4fa0d4edf01483a72b881afe.jpg)
[implementation of depth first search]

Trees and binary trees: traversal of binary trees

C language: deep understanding of pointers and arrays
随机推荐
Trees and binary trees: Construction of binary trees
LeetCode 583. Deleting two strings
1-4 message passing interface [CSP authentication]
SpEL表达式 简单使用
(dijkstra+ shortest path + edge traversal 0 (m)) acwing 850 Dijkstra finding the shortest path II
Dpdk timer learning notes
LeetCode 剑指 Offer 30. 包含min函数的栈
Standard template library (STL)
LeetCode 6098. Count the number of subarrays whose score is less than K (prefix and + binary search)
LeetCode 5289. 公平分发饼干(DFS)
I set up a blog
C language: data storage in memory
(Dijkstra + shortest circuit + by point n^2) acwing 849 Dijkstra finding the shortest path I
Exercise 7-7 string replacement (15 points)
Exploitation of competitive loopholes in attacking and defending world PWN play conditions
Routing - static routing
Solov2 nanny level tutorial (including environment configuration, training your own data set, code logic analysis, etc...) Updating ing
acwing 790. The third root of a number (dichotomy)
MOOC week 8 programming exercise 1
Lecture par lots de tous les fichiers vocaux sous le dossier

