Gray hair is God’s graffiti.
Bill Cosby

We are going to generate a sequence of integers in binary. Start with the sequence
0
1

    Reflect it in the horizontal line, prepend a zero to the numbers in the top half and a one to the numbers on the bottom and you will get
00
01
11
10
    Repeat this again, and you will have 8 numbers
000 0
001 1
011 3
010 2
110 6
111 7
101 5
100 4
    The corresponding decimal values are shown on the right.
    These sequences are called Reflected Gray Codes for 1, 2 and 3 bits respectively. A Gray Code for n bits is a sequence of 2n different n-bit integers with the property that every two neighbouring integers differ in exactly one bit. A Reflected Gray Code is a Gray Code constructed in the way shown above.
Input
The first line of input gives the number of cases, N (at most 250000). N test cases follow. Each one is a line with 2 integers: n (1 ≤ n ≤ 30) and k (0 ≤ k < 2^n).
Output
For each test case, output the integer that appears in position k of the n-bit Reflected Gray Code.
Sample Input
14
1 0
1 1
2 0
2 1
2 2
2 3
3 0
3 1
3 2
3 3
3 4
3 5
3 6
3 7
Sample Output
0
1
0
1
3
2
0
1
3
2
6
7
5
4

问题链接:UVA11173 Grey Codes
问题简述:(略)
问题分析
    有关Grey码计算问题,不解释 。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA11173 Grey Codes */#include <bits/stdc++.h>using namespace std;const int N = 30;int grey(int n)
{if(n != 0 && n != 1) {for (int i = 0; i <= N; i++)if (n >= (1 << i) && n < (1 << (i + 1)))return (1 << i) + grey((1 << (i + 1)) - n - 1);}return n;
}int main()
{int t, n, k;scanf("%d", &t);while (t --) {scanf("%d%d", &n, &k);printf("%d\n", grey(k));}return 0;
}

UVA11173 Grey Codes【位操作】相关推荐

  1. TYUT-A专题题解(一)

    TYUT-A专题题解(一) 01A Ad Hoc UVA353 LA5247 Pesky Palindromes[回文] - 海岛Blog - CSDN博客 UVA947 Master Mind He ...

  2. Competitive Programming 3题解

    题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...

  3. RGB Color Codes Chart

    RGB Color Codes Chart RGB颜色空间 RGB颜色空间或RGB颜色系统,从红色.绿色和蓝色的组合中构造所有颜色. 红色.绿色和蓝色各使用8位,它们的整数值从0到255.这使得256 ...

  4. 《深入理解计算机系统》读书随笔-位操作

    最近开始读<深入理解计算机系统>这本书.对于书中提到的从程序员的角度解读计算机系统这一说法非常感兴趣,所以决定好好读一读.从开始接触计算机编程就是站在一个高级语言的层次,虽然对编译原理,操 ...

  5. 计算机32位操作系统最大识别到内存,win7 32位系统可以支持多大的内存_win7 的32位系统最大支持多少g的内存...

    大家都知道win7系统有32位和64位之分,而两者的安装配置是不一样的,一般4G内存的我们安装64位的系统,但是很多用户不知道win7 32位系统可以支持多大的内存,这就给大家分享一下win7 的32 ...

  6. java右移位_java、、移位操作方法

    < int leftShift = 10; System.out.println("十进制:" + leftShift + ", 二进制:" + Inte ...

  7. 论文:Multi-Objective Modified Grey Wolf Optimizer for Optimal Power Flow-最优潮流

    论文来源: Multi-objective Modified Grey Wolf Optimizer for ..._百度学术 http://xueshu.baidu.com/s?wd=Multi-O ...

  8. python使用matplotlib可视化、使用matplotlib可视化scipy.misc图像、自定义使用grey灰色映射、将不同亮度映射到不同的色彩、并添加颜色标尺

    python使用matplotlib可视化.使用matplotlib可视化scipy.misc图像.自定义使用grey灰色映射.将不同亮度映射到不同的色彩.并添加颜色标尺 目录

  9. python中二进制以什么开头_Python二进制表示和位操作

    我们都知道在计算机中所有的信息最终都是以二进制的0和1来表示,而有些算法是通过操作bit位来进行运算的,这就需要我们了解Python中如何去表示二进制,又如何是进行位运算的. 二进制的表示 首先在Py ...

最新文章

  1. 如何用Python批量提取PDF文本内容?
  2. 马云“赢在中国”对于80后创业者的忠告
  3. 实现迭代型的echo服务器
  4. 网关层面为何要用Lua
  5. 2013.5.21号面试心得
  6. Linux的secureCRT设置字体大小
  7. webpack4.0各个击破(2)—— CSS篇
  8. 转【微信小程序 四】二维码生成/扫描二维码
  9. qt for android 图片可拉伸,qt实现九宫格布局,图片拉伸
  10. windows cmd后ipconfig后提示不是内部命令或外部命令
  11. 张凯江:架构能力-“构建”世界的能力
  12. IOS基础学习日志(七)利用dispatch_once创建单例及使用
  13. CNN训练可视化特征图(tensorflow2.x实现)
  14. xp共享文件win7访问时不能保存密码
  15. Mybatis 传参问题
  16. 共建信创生态,助力组织国产化进程
  17. ITIL4实用指南 | ITSM的未来属于敏捷
  18. 呕心编写的《金牌网管师——金牌网吧网管》
  19. 用JAVA 创建自己的 A4 打印语言
  20. 数字和ASII码之间的转换

热门文章

  1. Ubuntu snap for 树莓派
  2. linux内核mtd驱动程序与sd卡驱动程序,Linux内核MTD驱动程序与SD卡驱动程序(2)
  3. 手机横版动作类游戏的开发思路
  4. C#图片处理之:Gamma校正
  5. 计算机二级分省和国家吗,计算机国家二级和省二级有什么区别?
  6. python中队列的应用用场景_消息队列使用的四种场景介绍
  7. 四、Mysql安装多实例
  8. spark运行wordcount
  9. 3dmax 计算机中丢失,3DMax如何找回丢失的3D命令面板或工具栏
  10. python导入xlsx转为csv_Python 拆分工作表为单个工作簿