usaco2.14Hamming Codes
来源:互联网 发布:登录淘宝帐号 编辑:程序博客网 时间:2024/05/01 14:02
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 0100Bit differences: xxx xx
Since five bits were different, the Hamming distance is 5.
PROGRAM NAME: hamming
INPUT FORMAT
N, B, D on a single line
SAMPLE 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 7682 85 97 102 120 127
枚举
/* ID: your_id_here PROG: hamming LANG: C++*/#include <iostream>#include<cstdio>#include<cstring>#include<stdlib.h>#include<algorithm>using namespace std;int di[100],b,n,d;int judge(int x){ int i,k=0; for(i = 0 ; i < b ; i++) { if((1<<i)&x) { k++; } } if(k>=d) return 1; return 0;}int main(){ freopen("hamming.in","r",stdin); freopen("hamming.out","w",stdout); int i,j,g=1; di[1] = 0; cin>>n>>b>>d; for(i = 1; i <= (1<<b); i++) { for(j = 1 ; j <= g ; j++) { if(!judge(di[j]^i)) break; } if(j==g+1) { g++; di[g] = i; } if(g==n) break; } for(i = 1; i <= n ; i++) { if(i%10!=1) cout<<" "; cout<<di[i]; if(i%10==0) puts(""); } if(n%10!=0) puts(""); fclose(stdin); fclose(stdout); return 0;}
- usaco2.14Hamming Codes
- USACO2.1.5 Hamming Codes (hamming)
- USACO2.1.5 Hamming Codes (hamming)
- Hamming Codes
- Hamming Codes
- Hamming Codes
- Hamming Codes
- USACO 2.1 Hamming Codes (hamming)
- 【搜索】【USACO】Hamming Codes
- 2.1.6 Hamming Codes
- Section 2.1 Hamming Codes
- 2.1Hamming Codes
- usaco training-Hamming Codes
- Hamming Codes 海明码
- usaco Hamming Codes
- USACO:Hamming Codes
- USACO-Hamming Codes
- 2.1.5---Hamming Codes
- C语言运算符优先级 详细列表
- 计算机网络基础教程
- 程序员学习能力提升三要素
- php
- 理解AOP
- usaco2.14Hamming Codes
- MySQL 5.6 测试之 Replication(主从复制)
- ARM平台上蓝牙协议栈Bluez的移植使用和配置
- 多线程编程2 例程3-4(Win32 API)
- DFS遍历
- “感动中国”2012年度人物颁奖词
- sql常用语句
- Android Dialog用法
- Python3.0 新特性