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 ...
随机推荐
- css3实现饼状图进度及环形进度条
1 <!-- 饼图 --> <div class="pie"></div> <hr /> <!-- 环形图 --> &l ...
- 10.Linux用户权限
1.权限基本概述 1. 什么是权限? 我们可以把它理解为操作系统对用户能够执行的功能所设立的限制,主要用于约束用户能对系统所做的操作,以及内容访问的范围,或者说,权限是指某个特定的用户具有特定的系统资 ...
- 你必须知道的容器监控 (2) cAdvisor
本篇已加入<.NET Core on K8S学习实践系列文章索引>,可以点击查看更多容器化技术相关系列文章.上一篇我们了解了docker自带的监控子命令以及开源监控工具Weave Scop ...
- 【网络安全】Dos攻击科普文
目录 DOS攻击 什么是DOS攻击 攻击手段分类 具体的攻击方式举例 优秀博客参考 DDOS攻击 DOS攻击 什么是DOS攻击 DOS是Denial of Service的简称,用中文简单翻译就是拒绝 ...
- 轻量级CNN模型mobilenet v1
mobilenet v1 论文解读 论文地址:https://arxiv.org/abs/1704.04861 核心思想就是通过depthwise conv替代普通conv. 有关depthwise ...
- Hystrix dashboard - Unable to connect to Command Metric Stream.
在使用boot 2.0.*以上版本 + cloud Finchley.RELEASE 查看仪表盘的时候会报错 Unable to connect to Command Metric Stream &l ...
- hdfs 文件系统命令操作
hdfs 文件系统命令操作 [1]hdfs dfs -ls [目录]. 显示所有文件 hdfs dfs -ls -h /user/20170214.txt 显示文件时,文件大小以人易读的形式显示 [2 ...
- python pyinstaller 打包exe报错
今天用python 使用pyinstaller打包exe出现错误 环境pyqt5 + python3.6 在导入pyqt5包之前加上如下代码 import sysimport osif hasattr ...
- Java基础(二十五)Java IO(2)文件File类
File类是一个与流无关的类.File类的对象可以获取文件及其文件所在的目录.文件的长度等信息. 1.File对象的常用构造方法. (1)File(String pathname) File file ...
- 选择器, ,>,+,~
一.后代选择器 选取指定元素的后代元素 与子元素选择器相比,后代选择器选取的不一定是直接后代(儿子),而是作用于所有后代元素(儿子.孙子.重孙…)都可以. 二.(>)子元素选择器 选取某个元素的 ...