CF1368B

论审题的重要性

题面:https://codeforces.com/problemset/problem/1368/B

大致题意:规定字符串中为codeforces的不连续子串个数为k,给定数字,求最短的、子串个数至少为k的字符串

题解:易知,字符串长度为n时,尽可能平均分配即可使子串个数最大,故找到最小的n满足题设条件即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include<algorithm>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<vector>
#include<string>
#include<map>
#include<cstdio>
#include<list>
#include<stack>
#include<unordered_set>
using namespace std;
using ll = int64_t;
ll T, n, m, k;
ll tmp, a[300005];
int main()
{
T = 1;
//cin >> T;
while(T--)
{
cin >> k;
if(k==1)
{
cout << "codeforces\n";
}else
{
ll pos = 1;
for (ll i = 1;;i++)
{
ll tem = 1;
for (ll j = 1; j <= 10;j++)
{
tem *= i;
}
if(tem>=k)
{
pos = i;
break;
}
}
ll sum = 1;
for (ll i = 1; i <= 10;i++)
{
a[i] = pos - 1;
sum *= a[i];
}
string s = "codeforces";
for (ll i = 1; i <= 10;i++)
{
if(sum<k)
{
a[i]++;
sum = sum / (a[i] - 1) * a[i];
}
for (ll j = 1; j <= a[i];j++)
{
cout << s[i - 1];
}
}
cout << "\n";
}

}
return 0;
}

注意k=1时要特判