CF1368B

题目简化和分析:

因为要求长度最小,所以我们每个字符就应该发挥最大的价值,不会有没有作用的字符。

设有 \(x_1\)\(c\)\(x_2\)\(o\)\(x_3\)\(d\)\(x_4\)\(e\)\(x_5\)\(f\)\(x_6\)\(o\)\(x_7\)\(r\)\(x_8\)\(c\)\(x_9\)\(e\)\(x_{10}\)\(s\) 。(均为连续)

则子序列的种数为 \(\prod_{i=1}^{10} a_i\)

为了使得 \(\sum_{i=1}^{10} a_i\) 的值最小,种数又最大,我们就要使得 \(a_i\) 的值都相对平均。

Solution:

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

const int N=1e5+50;
const int M=1e5+50;
const int Mod=1e9+7;

inline ll read(){
    ll x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}

ll k;

char c[15]={'c','o','d','e','f','o','r','c','e','s'};
ll res[15]={0,1,1,1,1,1,1,1,1,1,1};

ll sol(){
	ll tot=1;
	for(int i=1;i<=10;++i){
		tot*=res[i];
	}
	return tot;
}

int main()  
{
	k=read();
	int cnt=0;
	while(1){
		if(sol()>=k) break;
		cnt%=10;
		res[++cnt]++;
	}
	for(int i=0;i<10;++i){
		for(int j=1;j<=res[i+1];++j){
			printf("%c",c[i]);
		}
	}
	return 0;
}

posted @ 2022-08-17 12:48  RVG  阅读(28)  评论(0)    收藏  举报