您的位置:首页 > 其它

UVA 729 - The Hamming Distance Problem

2017-09-06 15:16 375 查看
题目大意:两个由01组成的字符串之间的汉明距离为两个字符串异或结果有几个1。输出字符串长度L以及汉明距离H,求与该长度为L字符全为0的字符串的汉明距离为H的所有字符串,字典次序列出全部。

解题思路:将第一个汉明距离为H的字符串读入即除了最后汉明距离长度的为1外,其他为0,然后用next_permutation列出所有。

ac代码:
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int n, len, H;
char st[20];
int main()
{
scanf("%d", &n);
while (n--){
scan
4000
f("%d%d", &len, &H);
for (int i=0; i<len; i++)
if (i >= len-H)
st[i] = '1';
else
st[i] = '0';
printf("%s\n", st);
while (next_permutation(st, st+len)) 
printf("%s\n", st);
if (n)
printf("\n");
memset(st, 0, sizeof(st));
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: