luoguP3014 [USACO11FEB]牛线Cow Line

Posted dream-runner

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了luoguP3014 [USACO11FEB]牛线Cow Line相关的知识,希望对你有一定的参考价值。

康拓展开- - 正运算会逆运算竟然忘了怎么写- - 晕死。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=25;
ll a[maxn],jie[maxn];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    jie[0]=1;
    for(int i=1;i<=n;++i)jie[i]=jie[i-1]*i;
    for(int i=1;i<=m;++i){
        char opt[2];
        scanf("%s",opt);
        if(opt[0]==P){
            ll k;
            scanf("%lld",&k);
            k--;
            vector<int>v;
            for(int i=1;i<=n;++i)v.push_back(i);
            for(int i=1;i<=n;++i){
                int t1=k/jie[n-i];
                k%=jie[n-i];
                a[i]=v[t1];
                v.erase(v.begin()+t1);
            }
            for(int i=1;i<=n;++i)printf("%d ",a[i]);
            printf("
");
        }
        else{
            ll ans=0;
            for(int i=1;i<=n;++i){
                scanf("%lld",&a[i]);
                int t1=a[i],t2=a[i];
                for(int j=1;j<=i;++j){
                    if(a[j]<=t1)--t2;
                }
                ans+=t2*jie[n-i];
            }
            printf("%lld
",ans+1);
        }
    }
    return 0;
}

 

以上是关于luoguP3014 [USACO11FEB]牛线Cow Line的主要内容,如果未能解决你的问题,请参考以下文章

洛谷P3014 [USACO11FEB]牛线Cow Line

[luoguP2870] [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold(后缀数组)

[USACO11FEB] Cow Line

luoguP2939 [USACO09FEB]改造路Revamping Trails

[luoguP2896] [USACO08FEB]一起吃饭Eating Together(DP)

[luoguP2875] [USACO07FEB]牛的词汇The Cow Lexicon(DP)