一道水题,简单的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定时删除文件脚本

    #! /bin/sh # 配置项DEBUG=truefolderDir=/var/www/html/hlsrecord/EXPIRE_DAY=1 # 过期时间和时间戳deadTime=`date -d ...

  2. Vmware tools install

    Vmware tools 1◆ 下载 2◆ diagram   Ifcfg-eth0   =====>关闭防火墙 systemctl stop firewalld.service   ===== ...

  3. oracle 如何查看当前用户的表空间名称

    如何查询当前用户的表空间名称?因为oracle建立索引,需要知道当前用户的表空间,查找了一下资料 --查询语法-- select default_tablespace from dba_users w ...

  4. Linux int 最大为多大

    可以查看 /usr/include/limits.h 文件 里面定义好了各种类型的最大最小值 ... /* Minimum and maximum values a `signed int' can ...

  5. codeigniter在nginx下返回404 not found

    codeigniter框架需要path_info的支持,Apache默认支持path_info,但是nginx默认不支持,我们需要设置nginx,使得nginx支持path_info 网上试了好多方法 ...

  6. Cyclic Components CodeForces - 977E(DFS)

    Cyclic Components CodeForces - 977E You are given an undirected graph consisting of nn vertices and  ...

  7. 线性回归之决定系数(coefficient of determination)

    1. Sum Of Squares Due To Error 对于第i个观察点, 真实数据的Yi与估算出来的Yi-head的之间的差称为第i个residual, SSE 就是所有观察点的residua ...

  8. ASP.Net MVC(4) 之js css引用与压缩

    资源引用 可以用即可以直接使用“~”来表示根目录. 引入js <script src="~/Areas/OrderManage/JS/Form.js"></scr ...

  9. node代理服务器

    var express = require('express');var request = require('request');var app = express();var _URL = 'ht ...

  10. ural1519

    题解: 插头dp 具体可以看看cdq论文 代码: #include<bits/stdc++.h> using namespace std; typedef long long ll; ; ...