一道水题,简单的next_permutation用法,相同的还有prev_permutation 包含在头文件<algorithm>中

字符串 acab 含有两个a ,一个b ,一个c ,和acab 含的字母和每个字母的个数都相等的字符串还有:aacb,baca等,因为他们也是含有两个a ,一个b ,一个c。 所有满足这个性质的字符串按字典顺序排列后,acab 是第5个,我们就说acab的序号是5。 再如:ba的序号是2,aa 的序号是1。 编程求出给定字符串 S(长度<=100)的序号 P(保证<=30000) 注意:字符串只含小写字母。

 #include <iostream>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <stack>
#include <queue>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const double Pi=3.14159265358979323846;
typedef long long ll;
const int MAXN=+;
const int dx[]={,,,-};
const int dy[]={,-,,};
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll mod=1e9+;
int main()
{
string str;cin>>str;
string str0=str;
sort(str0.begin(),str0.end());
int cnt=; while(str0!=str)
{
cnt++;
next_permutation(str0.begin(),str0.end());
}
cout <<cnt<<endl;
return ;
}

next_permutation(start,end)的更多相关文章

  1. 关于全排列 next_permutation() 函数的用法

    这是一个c++函数,包含在头文件<algorithm>里面,下面是基本格式. 1 int a[]; 2 do{ 3 4 }while(next_permutation(a,a+n)); 下 ...

  2. About next_permutation

    哈哈没错这个又是我们C++党的语言优势之一,用这个函数可以求当前排序的下一个排序,也就是说可以方便的求全排列,用这个函数需要用到algorithm这个头文件. 与这个函数相反的是prev_permut ...

  3. STL next_permutation和prev_permutation函数

    利用next_permutation实现全排列升序输出,从尾到头找到第一个可以交换的位置, 直接求到第一个不按升序排列的序列. #include <iostream> #include & ...

  4. 【STL】next_permutation的原理和使用

    1.碰到next_permutation(permutation:序列的意思) 今天在TC上碰到一道简单题(SRM531 - Division Two - Level One),是求给定数组不按升序排 ...

  5. (转)ACM next_permutation函数

    转自 stven_king的博客 这是一个求一个排序的下一个排列的函数,可以遍历全排列,要包含头文件<algorithm>下面是以前的笔记  (1) int 类型的next_permuta ...

  6. next_permutation函数

    这是一个求一个排序的下一个排列的函数,可以遍历全排列,要包含头文件<algorithm>下面是以前的笔记    与之完全相反的函数还有prev_permutation  (1) int 类 ...

  7. buaaoj230——next_permutation的应用

    题目地址 简单的全排列输出,借用stl中的next_permutation就非常简单了. 关于next_permutation:(备忘,来源网络) /*这是一个求一个排序的下一个排列的函数,可以遍历全 ...

  8. [算法]——全排列(Permutation)以及next_permutation

    排列(Arrangement),简单讲是从N个不同元素中取出M个,按照一定顺序排成一列,通常用A(M,N)表示.当M=N时,称为全排列(Permutation).从数学角度讲,全排列的个数A(N,N) ...

  9. [LeetCode] next_permutation

    概念 全排列的生成算法有很多种,有递归遍例,也有循环移位法等等.C++/STL中定义的next_permutation和prev_permutation函数则是非常灵活且高效的一种方法,它被广泛的应用 ...

  10. next_permutation 和 一个不成功的案例

    一个失败的案例:(POJ 1009) 题目描述 小翔同学的宿舍WIFI添加了密码,密码每天都会变更.而小翔每天都会给蹭网的同学们提供密码提示.现在请你根据密码提示,编写程序破译密码. 已知密码提示给出 ...

随机推荐

  1. Linux查看操作系统版本命令

    有时候比如在决定下载软件版本的时候,我们需要确定当前系统的位数和发行版版本. 命令 作用 适用说明 uname -a 显示Linux内核版本和位数 通用,推荐 cat /proc/version 显示 ...

  2. Qt绘制字体并获取文本宽度

    参考资料: https://blog.csdn.net/liang19890820/article/details/51227894 QString text("abc");QPa ...

  3. chrome google mozilla firefox bookmarks import export

    chrome导出导入bookmarks 1◆ google帐号 自己申请,脑补   2◆ google访问 脑补   suggestion   Lantern   3◆ 步骤 4◆ 导入 sample ...

  4. linux下uptime命令详解

    uptime uptime 另外还有一个参数 -V(大写),是用来查询版本的 procps是一个实用程序包,主要包括ps top kill等程序主要用来显示与控制一些系统信息,进程状态之类的内容. 以 ...

  5. decltype的参数是左值时,得到一个引用类型

    int* a = new int(10); decltype(*a) 得到的是引用类型:int&

  6. 逆袭之旅DAY17.东软实训.Oracle.存储过程

    2018-07-13 09:08:36

  7. learning at commad AT+CPSI

    [Purpose] Learning how to get mobile network info [Eevironment] Shell terminal, base on gcom command ...

  8. java新随笔

    1.纯随机数发生器 Xn+1=(aXn + c)mod m Modulus=231-1=int.MaxValue Multiplier=75=16807 C=0 当显示过2^31-2个数之后,才可能重 ...

  9. vue安装与配置

    直接引入 <script src="https://unpkg.com/vue"></script> 用npm安装   $ npm install vue ...

  10. debian服务器解决中文安装后出现乱码的问题

    由于安装debian选择语言时选择了简体中文安装,但内核没有中文字库,导致某些字符显示为乱码(菱形,方块). 解决办法: 普通用户如果没有设置sudo权限,首先切换到root权限.然后: apt-ge ...