Hamming Codes chapter 2.1
2013-08-25 13:47
218 查看
感觉USCAO的题目真是有点难懂,题目比较简单,直接从最小开始枚举就过了
/* ID: hubiao cave PROG: hamming LANG: C++ */ #include<iostream> #include<fstream> #include<string> #include<cmath> using namespace std; int N,B,D; int ary[66]; int count1=0; bool canfit(int); int main() { ifstream fin("hamming.in"); ofstream fout("hamming.out"); fin>>N>>B>>D; ary[1]=0; count1++; for(int i=1;i<=pow(2,B)-1&&count1<N;i++) { if(canfit(i)) ary[++count1]=i; } int i=1; while(i<N) { if(i%10!=0) { fout<<ary[i]<<" "; } else { fout<<ary[i]<<endl; } i++; } if((i+1)%10==0) fout<<ary[i]<<endl; else { fout<<ary[i]<<endl; } return 0; } bool canfit(int n) { for(int i=1;i<=count1;i++) { if(n==ary[i]) return false; int x=n^ary[i]; int cou=0; int m=0; while(cou<D&&m<B) { if(x>>m&1) cou++; m++; } if(cou<D) return false; } return true; }
相关文章推荐
- USACO Section 2.1 Hamming Codes - 题意相当坑爹..很无聊..
- USACO-Section2.1 Hamming Codes [搜索]
- USACO Hamming Codes 2.1
- Chapter 2.1 Hadoop的安装
- Add Image verification codes To CS2.1
- Healthy Holsteins chapter 2.1
- Chapter2.1 JVM内存管理一
- Chapter 2. URLs and Resources 2.1 Navigating the Internet's Resources
- chapter 2.1: 什么是windows Driver
- Chapter 2.1:WCF服务契约的重载与继承详解
- C++ primer 5 笔记2 chapter 2 变量和基本类型(2.1~2.3)
- Ordered Fractions chapter 2.1
- USACO :Hamming Codes 解题报告
- Section 2.1 hamming
- Hamming Codes
- usaco-2.1-hamming-pass
- c++primer4 Chapter2变量和基本类型2.1
- USACO Hamming Codes
- usaco 2.1 hamming 2008.6.10
- 《C++ primer 5》 chapter 2.1