UVA 729 The Hamming Distance Problem
2016-07-26 21:24
363 查看
UVA-729
题意:balabala了一堆,其实就是求n位01串中有 h 个1的所有序列。解题思路:STL中有一个求字符串字典序下一个字符的函数。next_permutation(c,c+n)。第一个是起始位置,后一个是结束位置。类似sort。然后只要把第一个(n-h个)0+ (h个)1的串弄出来。就好了。。
/************************************************************************* > File Name: UVA-729.cpp > Author: Narsh > > Created Time: 2016年07月26日 星期二 16时33分32秒 ************************************************************************/ #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; int t,n,h; char c[20]; int main() { scanf("%d",&t); while (t--) { scanf("%d%d",&n,&h); memset(c,0,sizeof(c)); for (int i = 0; i < n-h; i++) c[i]='0'; for (int i = n-h; i < n; i++) c[i]='1'; cout<<c<<endl; while (next_permutation(c,c+n)) cout<<c<<endl; if (t) printf("\n"); } }
相关文章推荐
- 解决jquery操作checkbox火狐下第二次无法勾选问题
- ubuntu下取代ping的好工具tcpping
- 联合使用DatePicker和TimePicker来选择日期和时间
- 22.css定义width和height的大小
- iOS设计模式之代理模式
- nfs学习
- HDU 5083/BC 15B Instruction
- Can you solve this equation?<hdoj2199>
- Keil MDK调试时提示ERROR 57: illegal address的解决方法
- 随堂笔记第一天:运算符,if和switch,标识符------2
- HDU 5753 Permutation Bo (找规律)
- Test
- 【Light-oj】-Expanding Rods(二分&几何)
- 数三角形(codevs 3693)
- [转] C#2010 在TreeView控件下显示路径下所有文件和文件夹
- 基于注解的spring多数据源配置
- 广元市贫困县第一书记
- html 超出用...代替
- HttpClient的使用和封装
- 网站开发基础知识篇二 JavaScript知识点