zoukankan      html  css  js  c++  java
  • 2.1.5 Hamming Codes

    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):

            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 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 76
    82 85 97 102 120 127
    
    {
    ID: makeeca1
    PROG: hamming
    LANG: PASCAL
    }
    var N,B,D,i,j:longint;bool:boolean;
        f:array[0..100]of longint;
    function work(x:longint):boolean;
    var i:longint;
    begin
      i:=0;
      while x>0 do begin if x and 1=1 then inc(i);x:=x>>1;end;
      if i>=d then exit(true);exit(false);
    end;
    begin
      assign(input,'hamming.in');reset(input);
      assign(output,'hamming.out');rewrite(output);
      readln(N,B,D);close(input);
      fillchar(f,sizeof(f),0);f[0]:=1;
      repeat
        inc(i);bool:=true;
        for j:=1 to f[0]do
          bool:=bool and (work(i xor f[j]));
        if bool then begin inc(f[0]);f[f[0]]:=i;end;
      until f[0]=N;
      for i:=1 to N-1 do
      begin
        write(f[i]);
        if i mod 10=0 then writeln else write(' ');
      end;
      writeln(f[N]);
      close(output);
    end.
  • 相关阅读:
    根据输入参数,判定时间范围CheckTimeSpan
    C#登出系统并清除Cookie
    MySQL中使用group_concat遇到的坑
    MySQL中group by 与 order by 一起使用排序问题
    使用VMware安装CentOS 7
    VMware安装Linux提示此主机支持 Intel VT-x,但 Intel VT-x 处于禁用状态
    Yii2处理密码加密及验证
    Yii2 的安装及简单使用
    git merge的使用
    PHP中上传文件打印错误,错误类型
  • 原文地址:https://www.cnblogs.com/makeecat/p/3274559.html
Copyright © 2011-2022 走看看