Hamming Codes

 对于题目中最后一句话不是怎么理解:
if interpreted as a base 2^B integer, would have the least value.
是把什么转换成2^B进制?
最小值指的是谁?
还有为什么答案第一个数是0
假设序列为A=(x1,x2,……,xn-1)
A-x1=(0 , x2-x1,……,xn-1 -x1 )
约减去一个相同的数它们的海明码不变?

请求大牛解答.

 

根据别人的思路A的代码:

#include<iostream> #include <string.h> #include <cstdio> using namespace std ; int main ( ) { freopen ( "hamming.in" , "r" , stdin ) ; freopen ( "hamming.out" , "w" , stdout ) ; int n , b , d ; cin >> n >> b >> d ; int maxi = 1 << b ; int i , j ; int ans [ 64 ] = { 0 } , cnt = 1 ; for ( i = 1 ; i < maxi ; i ++ ) { bool flag = true ; for ( j = 0 ; j < cnt && flag ; j ++ ) { int tmp = i ^ ans [ j ] ; int check = 0 ; while ( tmp ) { int lowbit = tmp & ( - tmp ) ; tmp -= lowbit ; check ++ ; } if ( check < d ) flag = false ; } if ( flag ) { ans [ cnt ++ ] = i ; if ( cnt >= n ) break ; } } cout << ans [ 0 ] ; if ( n > 1 ) cout << ' ' ; else cout << endl ; for ( i = 1 ; i < cnt - 1 ; i ++ ) { cout << ans [ i ] ; if ( i % 10 == 9 ) cout <<endl ; else cout << ' ' ; } cout << ans [ i ] << endl ; return 0 ; }

你可能感兴趣的:(Integer)