NYOJ 19 擅长排列的小名 next_permutation()的用法
2016-12-06 19:36
295 查看
主要就是next_permutation()这个函数的使用,没啥技术含量。
next_permutation()这使用时一定要保证参数是升序的,prev_permutation()与之相反否则生成的排列不全。具体原因看博客http://leonard1853.iteye.com/blog/1450085
本题代码
next_permutation()这使用时一定要保证参数是升序的,prev_permutation()与之相反否则生成的排列不全。具体原因看博客http://leonard1853.iteye.com/blog/1450085
本题代码
#include<iostream> #include<algorithm> #include<string> using namespace std; int main() { int t, i; cin>>t; while(t--) { int x, y; string s1, s2; cin>>x>>y; for(i = 1; i <= x;i++) { s1 += '0' + i; }//这里已经是升序了,所以不用再次排序。 s2 = s1.substr(0,y);//复制子串,即复制s1的前y个。 cout<<s2<<endl; while(next_permutation(s1.begin(),s1.end()))//参数要是升序的。 { if(s2 != s1.substr(0,y)) { s2 = s1.substr(0,y); cout<<s2<<endl; } } } return 0; }
相关文章推荐
- 黑客帝国代码流动效果(canvas)
- 如何关闭tomcat的localhost_access_log?
- UVA 11604
- java线程
- 加速度计和陀螺仪数据融合
- [置顶] Spring原理(四)AOP的实现
- poj 1125 Stockbroker Grapevine Floyd(基础题)
- [置顶] RxJava 使用场景小结
- <C++>_函数重载
- JMeter学习-026-JMeter 分布式(远程)参数化测试实例
- 简易计算器
- Scikit-learn环境的搭建
- Redis的持久化机制
- win7装linux双系统
- 变量提升/函数提升
- 枚举类型enum用法
- DES 加密 解密算法
- 十四周项目二(1)
- 图标的旋转动画
- 播放一个数组中的动画