1. 程式人生 > >Codeforces Round #431 (Div. 2) C

Codeforces Round #431 (Div. 2) C

次數 reat bits bar solution sage das ces eno

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