比赛 |
位运算及及其应用题单 |
评测结果 |
AAAAAAAAAA |
题目名称 |
海明码 |
最终得分 |
100 |
用户昵称 |
dy |
运行时间 |
0.030 s |
代码语言 |
C++ |
内存使用 |
3.29 MiB |
提交时间 |
2025-01-25 15:02:12 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int n,b,d;
int ans[114514];
int cnt=1,i=1;
bool f;
int find(int x,int y)
{
int u=x^y,res=0;
while(u)
{
if(u&1)res++;
u>>=1;
}
return res;
}
int main()
{
freopen("hamming.in","r",stdin);
freopen("hamming.out","w",stdout);
cin>>n>>b>>d;
while(cnt<n)
{
f=1;
for(int j = cnt ; j >= 1 ; j -- )
{
if(find(ans[j],i)<d)
{
f=0;
break;
}
}
if(f)
{
ans[++cnt]=i;
}
i++;
}
for(int i = 1 ; i <= cnt ; i ++ )
{
cout<<ans[i]<<" ";
if(i%10==0)cout<<"\n";
}
return 0;
}