usaco——hamming
2010-02-18 13:35
218 查看
Hamming Codes
Rob Kolstad
Given N, B, and D: Find a set of N codewords (1 <= N <= 64), each of length B bits (1 <= B <= 8), such that each of the codewords is at least Hamming distance of D (1 <= D <= 7) away from each of the other codewords. The Hamming distance between a pair of codewords is the number of binary bits that differ in their binary notation. Consider the two codewords 0x554 and 0x234 and their differences (0x554 means the hexadecimal number with hex digits 5, 5, and 4):
Since five bits were different, the Hamming distance is 5.
Rob Kolstad
Given N, B, and D: Find a set of N codewords (1 <= N <= 64), each of length B bits (1 <= B <= 8), such that each of the codewords is at least Hamming distance of D (1 <= D <= 7) away from each of the other codewords. The Hamming distance between a pair of codewords is the number of binary bits that differ in their binary notation. Consider the two codewords 0x554 and 0x234 and their differences (0x554 means the hexadecimal number with hex digits 5, 5, and 4):
0x554 = 0101 0101 0100 0x234 = 0010 0011 0100 Bit differences: xxx xx
Since five bits were different, the Hamming distance is 5.
PROGRAM NAME: hamming
INPUT FORMAT
N, B, D on a single lineSAMPLE INPUT (file hamming.in)
16 7 3
OUTPUT FORMAT
N codewords, sorted, in decimal, ten per line. In the case of multiple solutions, your program should output the solution which, if interpreted as a base 2^B integer, would have the least value.SAMPLE OUTPUT (file hamming.out)
0 7 25 30 42 45 51 52 75 76 82 85 97 102 120 127
/* ID: guangxue1 PROG: hamming LANG: C++ */ #include <fstream> using namespace std; int N,B,D; int ans[64]; bool Is(int a,int b) { int cnt=0; for(int i=0; i<B; ++i) {if((a&1)!=(b&1)) ++cnt; a=a>>1;b=b>>1;} if(cnt>=D) return true; else return false; } bool Is2(int top,int b) { for(int i=0; i<top; ++i) if(!Is(ans[i],b)) return false; return true; } void solve() {int cnt=1; int count=1; while(cnt<N) { if(Is2(cnt,count)) {ans[cnt]=count; ++cnt;} count++; } } int main() { ifstream fin("hamming.in"); ofstream fout("hamming.out"); fin>>N>>B>>D; solve(); for(int i=0,j=1; i<N-1; ++i,++j) { if(j<10) fout<<ans[i]<<' '; else {fout<<ans[i]<<endl; j=0;} } fout<<ans[N-1]<<endl; return 0; }[/code]
相关文章推荐
- USACO holstein, hamming
- usaco 2.1.5 hamming
- usaco Hamming Codes
- USACO Hamming Codes 2.1
- usaco 2.1 hamming 2008.6.10
- USACO2.1.5 Hamming Codes (hamming)
- usaco2.1 hamming(blog 写到一半发现大事不妙
- USACO2.1.5 Hamming Codes (hamming)
- USACO Hamming Codes
- 从usaco hamming Codes谈FP思想及FP技巧
- USACO Hamming Codes
- USACO hamming 继续暴搜
- usaco2.1.5(hamming)
- USACO-Section2.1 Hamming Codes [搜索]
- usaco 2.1 hamming...枚举...
- USACO :Hamming Codes 解题报告
- USACO 2.1 Hamming Codes (hamming)
- USACO Section 2.1 Hamming Codes - 题意相当坑爹..很无聊..
- usaco-2.1-hamming-pass
- USACO Hamming Codes 求汉明距离