首页 > 其他分享 >康托展开和康托逆展开

康托展开和康托逆展开

时间:2023-01-27 11:44:39浏览次数:32  
标签:int 康托逆 str tie 展开 康托

#include<bits/stdc++.h>
using namespace std;
int f[20];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    f[0]=1;
    for(int i=1;i<=10;++i)
    f[i]=i*f[i-1];
    string str;
    cin>>str;//54321
    int l=str.size();
    int ans=1;//康托展开编号从0开始
    for(int i=0;i<l;++i)
    {
        int cnt=0;
        for(int j=i+1;j<l;++j)
        if(str[j]<str[i]) cnt++;
        ans+=cnt*f[l-i-1];
    }
    cout<<ans<<'\n';//120
    int ord=120;
    ord--;
    for(int i=1;i<=5;++i)
    {
        int t=ord/f[l-i];//找到第t+1大的数
        cout<<t+1;//54321
        ord%=f[l-i];
    }
    return 0;
}

 

标签:int,康托逆,str,tie,展开,康托
From: https://www.cnblogs.com/ruoye123456/p/17068763.html

相关文章