nyoj 366 [【next_permutation()函数学习】
来源:互联网 发布:mac补丁 for vm10 编辑:程序博客网 时间:2024/05/19 04:55
D的小L
时间限制:4000 ms | 内存限制:65535 KB
难度:2
- 描述
- 一天TC的匡匡找ACM的小L玩三国杀,但是这会小L忙着哩,不想和匡匡玩但又怕匡匡生气,这时小L给匡匡出了个题目想难倒匡匡(小L很D吧),有一个数n(0<n<10),写出1到n的全排列,这时匡匡有点囧了,,,聪明的你能帮匡匡解围吗?
- 输入
- 第一行输入一个数N(0<N<10),表示有N组测试数据。后面的N行输入多组输入数据,每组输入数据都是一个整数x(0<x<10)
- 输出
- 按特定顺序输出所有组合。
特定顺序:每一个组合中的值从小到大排列,组合之间按字典序排列。 - 样例输入
223
- 样例输出
1221123132213231312321
next_permutation(),从小到大全排列。
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;int main(){ int t,n,i; int a[12]; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=0;i<n;i++) { a[i]=i+1; } do { for(i=0;i<n;i++) printf("%d",a[i]); printf("\n"); }while(next_permutation(a,a+n)); } return 0;}
最优代码:#include<iostream>#include<algorithm>using namespace std;int a[]={1,2,3,4,5,6,7,8,9};int main(){int n,r;cin>>r;while(r--){ cin>>n; do { for(int i=0;i<n;i++) cout<<a[i]; cout<<endl; }while(next_permutation(a,a+n));} return 0;}
0 0
- nyoj 366 [【next_permutation()函数学习】
- NYOJ 366 D的小L(从小到大输出排列。STL,next_permutation()函数的学习)
- nyoj+排列使用了next_permutation函数
- Nyoj-366 D的小L (全排列函数next_permutation的应用)
- next_permutation函数
- next_permutation函数
- next_permutation()函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- (七)JavaScript string对象及方法
- LeetCode-110.Balanced Binary Tree
- Path Sum
- tcp数据报头解析
- ASCLL码表的区域划分
- nyoj 366 [【next_permutation()函数学习】
- webService学习6:解析组件 's:schema' 时出错。在该组件中检测到 's:schem
- 硬链接与软链接
- 【杭电-oj】-2138-How many prime numberszz
- 关于农村土地确权系列博文的说明
- 51nod 1432 独木舟 贪心
- 创建oracle数据库
- [线性常微分方程][6]second order linear equations
- java局部内部类与方法里final变量的关系