nyoj 19 擅长排列的小明 【next_permutation() 】
来源:互联网 发布:手机淘宝怎么申请品牌 编辑:程序博客网 时间:2024/06/01 10:40
擅长排列的小明
时间限制:1000 ms | 内存限制:65535 KB
难度:4
- 描述
- 小明十分聪明,而且十分擅长排列计算。比如给小明一个数字5,他能立刻给出1-5按字典序的全排列,如果你想为难他,在这5个数字中选出几个数字让他继续全排列,那么你就错了,他同样的很擅长。现在需要你写一个程序来验证擅长排列的小明到底对不对。
- 输入
- 第一行输入整数N(1<N<10)表示多少组测试数据,
每组测试数据第一行两个整数 n m (1<n<9,0<m<=n) - 输出
- 在1-n中选取m个字符进行全排列,按字典序全部输出,每种排列占一行,每组数据间不需分界。如样例
- 样例输入
23 14 2
- 样例输出
123121314212324313234414243
next_permutation() 的有一应用,取n个数中的m个数的全排列。
对数组从1~n全排列,b[]存放a[]的前m个数,多组相同输出一组就好。
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;int main(){ int t,n,m,i; int a[12],b[12]; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(i=0;i<n;i++) a[i]=i+1; for(i=0;i<m;i++)//开始b[]是最小值 { b[i]=a[i]; printf("%d",b[i]); } printf("\n"); int f=0; do { for(i=0;i<m;i++)//b[]赋值更新 { if(a[i]!=b[i]) { f=1; b[i]=a[i]; } } if(f) { for(i=0;i<m;i++) printf("%d",b[i]); printf("\n"); f=0; } }while(next_permutation(a,a+n)); } return 0;}
0 0
- nyoj 19 擅长排列的小明 【next_permutation() 】
- NYOJ--19--next_permutation()--擅长排列的小明
- NYOJ 19 擅长排列的小明 (STL之next_permutation()的使用)
- NYOJ 19 擅长排列的小明(dsf STL——next_permutation函数)
- NYOJ19 擅长排列的小明【next_permutation】
- 擅长排列的小明(next_permutation)
- NYOJ 19 擅长排列的小明
- NYOJ 19-擅长排列的小明
- nyoj 19 擅长排列的小明
- nyoj 19 擅长排列的小明
- nyoj-19-擅长排列的小明
- nyoj 19 擅长排列的小明
- nyoj 19【擅长排列的小明】
- NYOJ 19 擅长排列的小明
- NYOJ 19(擅长排列的小明)
- NYOJ---19擅长排列的小明
- nyoj 19 擅长排列的小明
- NYOJ 19 擅长排列的小明
- 关于埋点
- https://github.com/espressif/esp8266_mp3_decoder
- ajax回调函数 异步延迟
- smtp协议
- linux文本处理 sort,grep,sed,awk,uniq 用法
- nyoj 19 擅长排列的小明 【next_permutation() 】
- java命令行下如何设置classpath类路径
- EasyCamera Android安卓移动视频监控单兵设备接入EasyDarwin开源流媒体云平台
- activity 四种启动方式
- leetcode 354. Russian Doll Envelopes
- 项目乐学成语HappyIdiom
- 韦东山 文件系统映像,mount挂接文件系统
- CentOS安装JDK1.7
- Codeforces645E Intellectual Inquiry