next_permutation(start,end)
生活随笔
收集整理的這篇文章主要介紹了
next_permutation(start,end)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一道水題,簡單的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) 注意:字符串只含小寫字母。
1 #include <iostream> 2 #include <cstring> 3 #include <string> 4 #include <map> 5 #include <set> 6 #include <algorithm> 7 #include <fstream> 8 #include <cstdio> 9 #include <cmath> 10 #include <stack> 11 #include <queue> 12 #define lson l,m,rt<<1 13 #define rson m+1,r,rt<<1|1 14 using namespace std; 15 const double Pi=3.14159265358979323846; 16 typedef long long ll; 17 const int MAXN=200+5; 18 const int dx[4]={0,0,1,-1}; 19 const int dy[4]={1,-1,0,0}; 20 const int INF = 0x3f3f3f3f; 21 const int NINF = 0xc0c0c0c0; 22 const ll mod=1e9+7; 23 int main() 24 { 25 string str;cin>>str; 26 string str0=str; 27 sort(str0.begin(),str0.end()); 28 int cnt=1; 29 30 while(str0!=str) 31 { 32 cnt++; 33 next_permutation(str0.begin(),str0.end()); 34 } 35 cout <<cnt<<endl; 36 return 0; 37 }?
轉載于:https://www.cnblogs.com/Msmw/p/10544847.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的next_permutation(start,end)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [Swift]LeetCode781.
- 下一篇: 201671030125+词频统计软件项