Codeforces Global Round 8 B. Codeforces Subsequences

题目链接

思路:通过排列组合找到最小的序列

#include 
#include 
#include 
#include 
#include
#include
using namespace std;
typedef long long ll;
#define SIS std::ios::sync_with_stdio(false)
#define space putchar(' ')
#define enter putchar('\n')
typedef pair<int,int> PII;
const int mod=1e4+7;
const int N=2e6+10;
const int inf=0x7f7f7f7f;


ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}

ll lcm(ll a,ll b)
{
    return a*(b/gcd(a,b));
}

template <class T>
void read(T &x)
{
    char c;
    bool op = 0;
    while(c = getchar(), c < '0' || c > '9')
        if(c == '-')
            op = 1;
    x = c - '0';
    while(c = getchar(), c >= '0' && c <= '9')
        x = x * 10 + c - '0';
    if(op)
        x = -x;
}
template <class T>
void write(T x)
{
    if(x < 0)
        x = -x, putchar('-');
    if(x >= 10)
        write(x / 10);
    putchar('0' + x % 10);
}int a[12];
int main()
{
    SIS;
    ll n;
    string x="codeforces";
    cin>>n;
    for(int i=0;i<10;i++)
        a[i]=1;
    ll ans=1;
    int cnt=0;
    while(ans<n)
    {
       ans/=a[cnt];///重复的去掉
       a[cnt]++;
       ans*=a[cnt];
       cnt++;
       if(cnt==10)cnt=0;
    }
    for(int i=0;i<10;i++)
    {
        for(int j=0;j<a[i];j++)
            cout<<x[i];
    }
    return 0;
}

你可能感兴趣的:(CF)