zoukankan      html  css  js  c++  java
  • 代码nullgray code

    最近使用开发的过程中出现了一个小问题,顺便记录一下原因和方法--代码null

        标题:

        The gray code is a binary numeral system where two successive values differ in only one bit.

        Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.

        For example, given n = 2, return [0,1,3,2]. Its gray code sequence is:

    00 - 0
    01 - 1
    11 - 3
    10 - 2

        Note:
    For a given n, a gray code sequence is not uniquely defined.

        每日一道理
    微笑着,去唱生活的歌谣,不要埋怨生活给予了太多的磨难,不必抱怨生命中有太多的曲折。大海如果失去了巨浪的翻滚,就会失去雄浑;沙漠如果失去了飞沙的狂舞,就会失去壮观。人生如果仅去求得两点一线的一帆风顺,生命也就失去了存在的意义。

        For example, [0,2,3,1] is also a valid gray code sequence according to the above definition.

        For now, the judge is able to judge based on one instance of gray code sequence. Sorry about that.

        代码如下:

        vector<int> grayCode(int n) {
            vector<int> result;
            int m=1<<n;
            for(int i=0;i<m;i++)
            {
                result.push_back(i^(i>>1));
            }
            return result;
        }

    文章结束给大家分享下程序员的一些笑话语录: Borland说我很有前途,Sun笑了;Sun说我很有钱,IBM笑了;IBM说我很专业,Sybase笑了;Sybase说我数据库很牛,Oracle笑了;Oracle说我是开放的,Linux笑了;Linux说我要打败Unix,微软笑了;微软说我的系统很稳定,我们都笑了。

    --------------------------------- 原创文章 By
    代码和null
    ---------------------------------

  • 相关阅读:
    Treap仿set 模板
    线段树(区间更改,区间查最值)模板
    UVA 12345 Dynamic len(带修莫队)
    服务器配置环境以及部署项目流程
    使用SSH的scp命令行传输文件到远程服务器
    服务器部署javaweb项目
    在ubuntu服务器上安装mysql并配置外网访问
    在ubuntu服务器上配置tomcat
    在ubuntu服务器上配置jdk
    linux命令--解压与压缩
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3104896.html
Copyright © 2011-2022 走看看