学习:

http://blog.sina.com.cn/s/blog_9f7ea4390101101u.html

http://blog.csdn.net/ac_gibson/article/details/45308645

https://blog.csdn.net/HowardEmily/article/details/68064377

next_permutation(start,end)和 prev_permutation(start,end)。

这两个函数作用是一样的,区别就在于:

前者求的是当前排列的下一个排列

后者求的是当前排列的上一个排列

至于这里的“前一个”和“后一个”,我们可以把它理解为序列的字典序的前后,

严格来讲,就是对于当前序列pn,他的下一个序列pn+1满足:不存在另外的序列pm,使pn<pm<pn+

用法: 通常用调入字符串或数组 头指针 和 头指针+对前几位进行全排列。

POJ 1256

 #include<iostream> //poj 1256 Anagram
#include<string>
#include<algorithm>
using namespace std;
int cmp(char a,char b) //自定义字典序
{
if(tolower(a)!=tolower(b))//tolower 是将大写字母转化为小写字母.
return tolower(a)<tolower(b);
else
return a<b;
}
int main()
{
char ch[];
int n;
cin>>n;
while(n--)
{
scanf("%s",ch);
sort(ch,ch+strlen(ch),cmp);
do
{
printf("%s\n",ch);
}while(next_permutation(ch,ch+strlen(ch),cmp));
}
return ;
}

STL - next_permutation 全排列函数的更多相关文章

  1. next_permutation() 全排列函数

    next_permutation() 全排列函数 这个函数是STL自带的,用来求出该数组的下一个排列组合 相当之好用,懒人专用 适用于不想自己用dfs写全排列的同学(结尾附上dfs代码) 洛谷oj可去 ...

  2. STL next_permutation 全排列

    调用方法: ]={,,,}; )){ ;i<;i++) printf("%d ",arr[i]); puts(""); } 测试效果: 注:可以看到1 2 ...

  3. C++ STL 全排列函数

    C++  全排列函数...一听名字就在<algorithm>中... 首先第一个说的是next_permutation: #include <algorithm> bool n ...

  4. 打印全排列和stl::next_permutation

    打印全排列是个有点挑战的编程问题.STL提供了stl::next_permutation完美的攻克了这个问题. 可是,假设不看stl::next_permutation,尝试自己解决,怎么做? 非常自 ...

  5. 2017年上海金马五校程序设计竞赛:Problem A : STEED Cards (STL全排列函数)

    Description Corn does not participate the STEED contest, but he is interested in the word "STEE ...

  6. 组合数学 + STL --- 利用STL生成全排列

    Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ( ...

  7. POJ1833 排列 调用全排列函数 用copy函数节省时间 即使用了ios同步代码scanf还是比较快

    排列 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 21268   Accepted: 8049 Description 题 ...

  8. unique && stl的全排列

    stl的全排列: 看代码. #include<iostream> #include<cstdio> #include<algorithm> #include< ...

  9. 3.2 STL中的函数对象类模板

    *: STL中有一些函数对象类模板,如下所示: 1)例如要求两个double类型的x 和y 的积,可以: multiplies<double>()(x,y); 该表达式的值就是x*y的值. ...

随机推荐

  1. PostgreSQL Entity Framework 自动迁移

    1.依次添加NuGet包 EntityFramework.Npgsql.EntityFramework6.Npgsql,会自动生成一些配置文件,不过缺少数据库驱动的配置节点: <system.d ...

  2. Centos时间查看修改命令date详解

    1.查看.修改Linux时区与时间 一.linux时区的查看与修改 1,查看当前时区date -R 2,修改设置时区方法1:tzselect 方法2:仅限于RedHat Linux 和 CentOSt ...

  3. (转)The remote certificate is invalid according to the validation procedure

    If you get “The remote certificate is invalid according to the validation procedure” exception while ...

  4. java 生成和解析xml

    本文主要使用的是Jdom.jar包(包的下载百度一下)实现了生成xml文件和解析xml文件 下面是生成xml的实现 说明:stuLists集合是一个存放着Student对象的集合 import jav ...

  5. javascript刷新页面的集中办法

    1. history.go(0) 2. location.reload() 3. location=location 4. location.assign(location) 5. document. ...

  6. Google自写插件详解

    谷歌插件详解,跳转至个人主页查看. GoogleExtension

  7. 操作Hadoop集群

    操作Hadoop集群 所有必要的配置完成后,将文件分发到所有机器上的HADOOP_CONF_DIR目录.这应该是所有机器上相同的目录. 一般来说,建议HDFS和YARN作为单独的用户运行.在大多数安装 ...

  8. C# 获取窗口句柄并且关闭应用程序

    原文:http://www.cnblogs.com/oraclejava/articles/1549025.html public class User32API { private static H ...

  9. 命令解决500 Error: Cannot find module 'XXX'

    装express之后访问http://localhost:3000.会出现500 Error: Cannot find module 'xxx'错误 解决方案: 确定package.json里有添加相 ...

  10. Eclipse 无法编译,提示“错误: 找不到或无法加载主类”

    jar包问题: 1.项目的Java Build Path中的Libraries中有个jar包的Source attachment指为了一个不可用的jar包, 解决办法是:将这个不可用的jar包remo ...