Codeforces Round #431 (Div. 2) C

Posted 樱花落舞

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #431 (Div. 2) C相关的知识,希望对你有一定的参考价值。

From beginning till end, this message has been waiting to be conveyed.

For a given unordered multiset of n lowercase English letters ("multi" means that a letter may appear more than once), we treat all letters as strings of length 1, and repeat the following operation n - 1 times:

  • Remove any two elements s and t from the set, and add their concatenation s + t to the set.

The cost of such operation is defined to be 技术分享, where f(s, c) denotes the number of times character cappears in string s.

Given a non-negative integer k, construct any valid non-empty set of no more than 100 000 letters, such that the minimum accumulative cost of the whole process is exactly k. It can be shown that a solution always exists.

Input

The first and only line of input contains a non-negative integer k (0 ≤ k ≤ 100 000) — the required minimum cost.

Output

Output a non-empty string of no more than 100 000 lowercase English letters — any multiset satisfying the requirements, concatenated to be a string.

Note that the printed string doesn‘t need to be the final concatenated string. It only needs to represent an unordered multiset of letters.

Examples
input
12
output
abababab
input
3
output
codeforces
Note

For the multiset {‘a‘, ‘b‘, ‘a‘, ‘b‘, ‘a‘, ‘b‘, ‘a‘, ‘b‘}, one of the ways to complete the process is as follows:

  • {"ab", "a", "b", "a", "b", "a", "b"}, with a cost of 0;
  • {"aba", "b", "a", "b", "a", "b"}, with a cost of 1;
  • {"abab", "a", "b", "a", "b"}, with a cost of 1;
  • {"abab", "ab", "a", "b"}, with a cost of 0;
  • {"abab", "aba", "b"}, with a cost of 1;
  • {"abab", "abab"}, with a cost of 1;
  • {"abababab"}, with a cost of 8.

The total cost is 12, and it can be proved to be the minimum cost of the process.

 题意:可能说的不清楚,我们取两个字符串,重复的我们把出现次数记录一下,然后相乘

a和b没有重复的,0*0

aba和b有一个重复的 1*1

然后。。为什么最后等于8了我也没想(为什么不是4*4或者1*1?)

反正最后我们加起来等于n就行

解法:

1 构造当然想最容易的 n=12

a a a a这种合并就很简单,0+1+2+3就行

2 我们拿5个a,花费了10,还差2

3 换个字母b,拿两个b b ,还差1

4 再换个字母c,两个c c 搞定

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 double x[1234];
 4 set<double>Se;
 5 double ans;
 6 int main(){
 7     int n;
 8     cin>>n;
 9     string s="";
10     if(n==0){
11         cout<<"a"<<endl;
12     }else{
13         char c=a;
14         while(n){
15             int sum=0;
16             int i=0;
17             for(i=0;sum<=n;i++){
18                 sum+=i;
19             }
20          
21             n-=(sum-i+1);
22             for(int j=0;j<i-1;j++){
23                 s+=c;
24             }
25             c++;
26         }
27         cout<<s<<endl;
28     }
29     return 0;
30 }

 

 

以上是关于Codeforces Round #431 (Div. 2) C的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #431 (Div. 2) A

Codeforces Round #431 (Div. 2) B

Codeforces Round #431 Div. 1

codeforces比赛题解#849 CF Round #431 (Div.2)

Codeforces Round #431 (Div. 1) D.Shake It!

Codeforces Round #436 E. Fire(背包dp+输出路径)