1721. Gray code
来源:互联网 发布:文明5黄金时代算法 编辑:程序博客网 时间:2024/06/13 13:42
看数点书吧,c++格式输出会超时。
#include <cstdio>#include <iostream>#include <cstring>#include <cmath>using namespace std;void gray(bool b[20],bool g[20],int len){ g[0]=b[0]; for(int i=1;i<len;i++) g[i]=(b[i-1]^b[i]);}void pplus(bool b[20],int len){ int i=len-1; while(true) { if(b[i]==1) b[i]=0; else if(b[i]==0) { b[i]++; break; } i--; }}int main(){ int t; bool arr[20],result[20]; while(scanf("%d",&t),t!=0) { memset(arr,0,sizeof(arr)); for(int i=0;i<pow(2.0,t);i++) { gray(arr,result,t); for(int j=0;j<t;j++) printf("%d",(int)result[j]); printf("\n"); pplus(arr,t); } printf("\n"); } return 0;}
- 1721. Gray code
- Sicily 1721. Gray code
- Sicily 1721. Gray code
- 1721. Gray code[Special judge]
- 1721. Gray code[Special judge]
- Gray Code
- Gray Code
- gray code
- Gray Code
- Gray Code
- Gray Code
- Gray Code
- Gray Code
- Gray Code
- Gray Code
- Gray Code
- Gray Code
- Gray Code
- firebird学习笔记
- 浅谈java中dao工厂设计模式
- <WP7>(三)手把手教你写天气预报程序:运用WebClient获取天气和json数据解析
- gem install eventmachine fail
- ClassWizard里面找不到WM_ACTIVATE消息解决
- 1721. Gray code
- 黑马程序员-学习-正则表达式
- C++ How To Program专业词汇Ch02
- *printf()格式化串安全漏洞分析(上)
- hibernate之无法解析hibernate.cfg.xml
- ubuntu从命令行启动的方法
- c语言 知识总结
- 今天各种坑 库连不上,apache装起来外面访问不了,fsockopen 权限不够
- [Frame(extraClass="XXXXXX")] 标签