/*
ID:lvfuan11
PROG:hamming
LANG:C++
translation:
给出n,b,d求出n个字典序最小的n个长度为b的01字符串,这些字符串两两满足其hamming距离大于等于d。
solution:
直接枚举即可,可以使用二进制来加速
*/
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int n, b, d;
vector<int> ans;
int hamming_dis(int x, int y)
{
int cnt = 0;
while(x || y) {
if((x & 1) != (y & 1))
cnt++;
x >>= 1;
y >>= 1;
}
return cnt;
}
bool check(int x)
{
if(ans.empty()) return true;
for(int i = 0; i < ans.size(); i++)
if(hamming_dis(ans[i], x) < d) return false;
return true;
}
int main()
{
freopen("hamming.in", "r", stdin);
freopen("hamming.out", "w", stdout);
while(~scanf("%d%d%d", &n, &b, &d)) {
ans.clear();
for(int i = 0; i < 2 << 8; i++) {
if(ans.size() == n) break;
if(check(i)) ans.push_back(i);
}
for(int i = 0; i < ans.size(); i++) {
printf("%d", ans[i]);
if((i + 1) % 10 == 0 || i + 1 == ans.size()) printf("\n");
else printf(" ");
}
}
return 0;
}
usaco2.1.5
最新推荐文章于 2024-04-25 22:04:29 发布