suseoj 1208: 排列问题 (STL, next_permutation(A.begin(), A.end()))
1208: 排列问题
时间限制: 1 Sec 内存限制: 128 MB
提交: 2 解决: 2
[提交][状态][讨论版][命题人:liyuansong]
题目描述
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
给定n个整数,现请编程求它们所有的全排列。
输入
输出
样例输入
3
1 23 88
样例输出
1 23 88
1 88 23
23 1 88
23 88 1
88 1 23
88 23 1 思路:
直接使用STL里面algorithm中的next_permutaion()方法 核心代码:
do{
for(int i = ; i < n; ++ i)
printf("%d ", A[i]);
printf("%d\n", A[]n-);
}while(next_permutation(A, A+n));
C/C++ 代码实现(AC):
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <stack>
#include <map>
#include <queue> using namespace std; int main()
{
int n, A[];
scanf("%d", &n);
for(int i = ; i < n; ++ i)
scanf("%d", &A[i]);
sort(A, A+n, less<int>());
do{
for(int i = ; i < n-; ++ i)
printf("%d ", A[i]);
printf("%d\n", A[n-]);
}while(next_permutation(A, A+n));
return ;
}
suseoj 1208: 排列问题 (STL, next_permutation(A.begin(), A.end()))的更多相关文章
- POJ 1833 排列【STL/next_permutation】
题目描述: 大家知道,给出正整数n,则1到n这n个数可以构成n!种排列,把这些排列按照从小到大的顺序(字典顺序)列出,如n=3时,列出1 2 3,1 3 2,2 1 3,2 3 1,3 1 2,3 2 ...
- 打印全排列和stl::next_permutation
打印全排列是个有点挑战的编程问题.STL提供了stl::next_permutation完美的攻克了这个问题. 可是,假设不看stl::next_permutation,尝试自己解决,怎么做? 非常自 ...
- nyoj19(排列组合next_permutation(s.begin(),s.end()))
题目意思: 从n个数中选择m个数,按字典序输出其排列. pid=19">http://acm.nyist.net/JudgeOnline/problem.php?pid=19 例: 输 ...
- STL next_permutation和prev_permutation函数
利用next_permutation实现全排列升序输出,从尾到头找到第一个可以交换的位置, 直接求到第一个不按升序排列的序列. #include <iostream> #include & ...
- C++ STL, next_permutation用法。
next_permutation 将按字母表顺序生成给定序列的下一个较大的序列,直到整个序列为 #include"iostream" #include"algorithm ...
- hdu1716排列2(stl:next_permutation+优先队列)
排列2 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- C++ STL next_permutation(快速排列组合)
排列组合必备!! https://blog.csdn.net/bengshakalakaka/article/details/78515480
- STL next_permutation 算法原理和实现
转载自:https://www.cnblogs.com/luruiyuan/p/5914909.html 目标 STL中的next_permutation 函数和 prev_permutation 两 ...
- STL next_permutation 算法原理和自行实现
目标 STL中的next_permutation 函数和 prev_permutation 两个函数提供了对于一个特定排列P,求出其后一个排列P+1和前一个排列P-1的功能. 这里我们以next_pe ...
随机推荐
- 小白学 Python(4):变量基础操作
人生苦短,我选Python 引言 前文传送门 小白学 Python(1):开篇 小白学 Python(2):基础数据类型(上) 小白学 Python(3):基础数据类型(下) 前面的文章中,我们介绍了 ...
- [BZOJ4990][Usaco2017 Feb]Why Did the Cow Cross the Road II
Description Farmer John is continuing to ponder the issue of cows crossing the road through his farm ...
- [BZOJ1833][ZJOI2010]数字计数
Description 给定两个正整数a和b,求在[a,b]中的所有整数中,每个数码(digit)各出现了多少次. Input 输入文件中仅包含一行两个整数a.b,含义如上所述. Output 输出文 ...
- LInux下npm install 安装失败问题
现象: 今天公司自己动部署的Jenkins出现了问题,在执行npm install的时候,失败了,下载不到npm,在查阅了各种报错信息之后还是没有解决,发现用淘宝镜像进行安装时,也会有安装不成功的情况 ...
- 基于canvas实现钟表
原理说明 1.通过arc方法实现钟表外环: 2.通过line实现钟表时针,分针,秒针和刻度标志的绘制,基于save和restore方法旋转画布绘制不同角度的指针: 3.通过font方法实现在画布上绘制 ...
- 原版_打字游戏.html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- jquery复习
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- ASP.NET Core如何使用压缩中间件提高Web应用程序性能
前言 压缩可以大大的降低我们Web服务器的响应速度,压缩从而提高我们网页的加载速度,以及节省一定的带宽. 何时使用相应压缩中间件 在IIS,Apache,Nginx中使用基于服务端的响应压缩技术.中间 ...
- jvm虚拟机栈的作用
jvm虚拟机栈的作用 jvm虚拟机栈栈帧的组成 jvm虚拟机栈,也叫java栈,它由一个个的栈帧组成,而栈帖由以下几个部分组成 局部变量表-存储方法参数,内部使用的变量 操作数栈-在变量进行存储时,需 ...
- 记 Maven 本地仓库埋坑之依赖包为何不能用
记一次 Maven 本地仓库埋坑之 Verifying Availability 背景 某 Java 后端项目使用 maven 构建,因为某些原因,某些依赖库下载不了,直接找其它人索要了他电脑上的 m ...