B. Codeforces Subsequences

思路:“codeforces”这个字符串中的每个位置的字符都只出现一次那么“codeforces”就只出现了一次,如果每个位置的字符都出现两次,那么“codeforces”就出现了2^10次,10是”codeforces“的长度。
题目要求要让”codeforces“至少出现k次,那么我们可以从第0个位置的字符开始计算,到当前字符为止,”codeforces“出现了多少次,和n进行比较;如果达到第9个位置了,那么下一次应该从第0个位置开始。
#include<bits/stdc++.h> using namespace std; const int maxn=2e5+10; long long a[maxn]; long long cha[maxn]; long long n; char s[10]={'c','o','d','e','f','o','r','c','e','s'}; int arr[10]; void solve(){ int cnt=0; while(1){ arr[cnt]++; cnt=(cnt+1)%10; long long sum=1; for(int i=0;i<10;i++){ sum*=arr[i]; } if(sum>=n) break; } for(int i=0;i<10;i++){ for(int j=0;j<arr[i];j++){ cout<<s[i]; } } return ; } void INPUT(){ scanf("%lld",&n); solve(); } int main() { INPUT(); //solve(); return 0; }

 

posted @ 2021-12-22 22:57  ZangYiDe  阅读(97)  评论(0)    收藏  举报