UVa 729 The Hamming Distance Problem (全排列输出&小细节)
来源:互联网 发布:python 上传图片 编辑:程序博客网 时间:2024/06/04 22:25
729 - The Hamming Distance Problem
Time limit: 3.000 seconds
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=670
The Hamming distance between two strings of bits (binary integers) is the number of corresponding bit positions that differ. This can be found by using XOR on corresponding bits or equivalently, by adding corresponding bits (base 2) without a carry. For example, in the two bit strings that follow:
A 0 1 0 0 1 0 1 0 0 0 B 1 1 0 1 0 1 0 1 0 0 A XOR B = 1 0 0 1 1 1 1 1 0 0
The Hamming distance (H) between these 10-bit strings is 6, the number of 1's in the XOR string.
Input
Input consists of several datasets. The first line of the input contains the number of datasets, and it's followed by a blank line. Each dataset contains N, the length of the bit strings and H, the Hamming distance, on the same line. There is a blank line between test cases.Output
For each dataset print a list of all possible bit strings of length N that are Hamming distance H from the bit string containing all 0's (origin). That is, all bit strings of length N with exactly H 1's printed in ascending lexicographical order.
The number of such bit strings is equal to the combinatorial symbol C(N,H). This is the number of possible combinations of N-H zeros and H ones. It is equal to
This number can be very large. The program should work for .
Print a blank line between datasets.
Sample Input
14 2
Sample Output
001101010110100110101100
加空字符啊。。。
完整代码:
/*0.032s*/#include<cstdio>#include<algorithm>using namespace std;char str[20];int main(void){int t, n, h, i;scanf("%d", &t);while (t--){scanf("%d%d", &n, &h);for (i = 0; i < n - h; ++i)str[i] = '0';for (; i < n; ++i)str[i] = '1';str[n] = '\0';///不要漏了!!!doputs(str);while (next_permutation(str, str + n));if (t) putchar('\n');}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 (全排列)
- 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
- 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
- 输入一行字符串,找出其中出现长度最长的字符串
- iOS多线程编程指南(一)关于多线程编程
- iOS多线程编程指南(二)线程管理
- 图像处理基础算法归类
- 关于产品的一些思考——360之360云盘
- UVa 729 The Hamming Distance Problem (全排列输出&小细节)
- Qt和Zbar的结合使用识别二维码条形码
- iOS多线程编程指南(四)线程同步
- web.xml语句顺序问题
- vba 将xml导入到excel
- 稀疏模型与结构性稀疏模型
- eclipse启动时 failed to create the java virtual machine 解决办法
- 优秀程序员不得不知道的20个位运算技巧
- iOS多线程编程指南(附录)