日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

next_permutation(start,end)

發布時間:2025/3/15 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。