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代码:
解题思路:将第一个汉明距离为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; }
相关文章推荐
- UVA 729 The Hamming Distance Problem
- uva 729 The Hamming Distance Problem
- UVa 729 - The Hamming Distance Problem
- UVA - 729 The Hamming Distance Problem
- uva 729 - The Hamming Distance Problem
- UVA 729 - The Hamming Distance Problem
- UVa-729-The Hamming Distance Problem
- UVA 729 The Hamming Distance Problem
- UVA - 729 The Hamming Distance Problem
- uva729 The Hamming Distance Problem
- UVa 729: The Hamming Distance Problem
- UVa-729-The Hamming Distance Problem
- UVA 729 The Hamming Distance Problem
- uva 729 - The Hamming Distance Problem
- UVa 729 - The Hamming Distance Problem
- UVa 729 The Hamming Distance Problem (全排列输出&小细节)
- UVa 729 The Hamming Distance Problem
- UVA 729 The Hamming Distance Problem
- UVa729 - The Hamming Distance Problem(全排列)
- UVa 729 - The Hamming Distance Problem