题目:

C. From Y to Y
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

思路:

  观察样例1很容易发现对于同一种字母,最小花费显然是是n*(n-1)/2,所以可以尝试用几个n*(n-1)/2去构造k。

  具体怎么证明没多想,用代码测了下发现都是对的,就写了一发。

 

 #include <bits/stdc++.h>

 using namespace std;

 #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; int k,cnt,ls,num,sum;
int main(void)
{
cin>>k;
if(k==)
{
printf("a\n");
return ;
}
while(k>)
{
ls=num=sum=;
while(k>=sum)
ls=sum,num++,sum+=num;
k-=ls;
for(int i=; i<=num; i++)
printf("%c",'a'+cnt);
if(k<=)break;
cnt++;
}
return ;
}

Codeforces Round #431 (Div. 2) C. From Y to Y的更多相关文章

  1. Codeforces Round #431 (Div. 1)

    A. From Y to Y time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. Codeforces Round #431 (Div. 2)

    A. Odds and Ends Where do odds begin, and where do they end? Where does hope emerge, and will they e ...

  3. 【Codeforces Round 431 (Div. 2) A B C D E五个题】

    先给出比赛地址啦,感觉这场比赛思维考察非常灵活而美妙. A. Odds and Ends ·述大意:      输入n(n<=100)表示长度为n的序列,接下来输入这个序列.询问是否可以将序列划 ...

  4. 【Codeforces Round #431 (Div. 2) B】 Tell Your World

    [链接]点击打开链接 [题意] n个点,x从左到右严格递增的顺序给出 让你划两条平行的,且没有相同点的直线; 使得它们俩各自最少穿过一个点. 且它们俩穿过了所有的点. [题解] 枚举第一个点和哪个点组 ...

  5. 【Codeforces Round #431 (Div. 2) C】From Y to Y

    [链接]点击打开链接 [题意] 让你构造一个大小最多为10W的字符multiset. 你进行n-1次操作; 每次操作,从set中取出两个字符串,一开始单个字符被认为是字符串. 然后把它们连接在一起. ...

  6. 【推导】【贪心】Codeforces Round #431 (Div. 1) A. From Y to Y

    题意:让你构造一个只包含小写字母的可重集,每次可以取两个元素,将它们合并,合并的代价是这两个元素各自的从‘a’到‘z’出现的次数之积的和. 给你K,你构造的可重集必须满足将所有元素合而为一以后,所消耗 ...

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

    ·最小割和组合数放在了一起,产生了这道题目. 英文题,述大意:     一张初始化为仅有一个起点0,一个终点1和一条边的图.输入n,m表示n次操作(1<=n,m<=50),每次操作是任选一 ...

  8. 【推导】【分类讨论】Codeforces Round #431 (Div. 1) B. Rooter's Song

    给你一个这样的图,那些点是舞者,他们每个人会在原地待ti时间之后,以每秒1m的速度向前移动,到边界以后停止.只不过有时候会碰撞,碰撞之后的转向是这样哒: 让你输出每个人的停止位置坐标. ①将x轴上初始 ...

  9. Codeforces Round #431 (Div. 2) C

    From beginning till end, this message has been waiting to be conveyed. For a given unordered multise ...

随机推荐

  1. hdu 4240在(最大流)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4240 思路:题意真的有点难理解:在城市A->B之间通过所有路径一小时之内能通过最大的车辆(Max ...

  2. C语言位运算+实例讲解(转)

    按位或 按位与 按位异或 按位取反 左移右移 C语言位运算 有6种: &, | , ^(亦或), >(右移). 注意:参与位运算的元素必须是int型或者char型,以补码形式出现. 按位 ...

  3. MVC模式 与 Model2模型 介绍

    Model1回顾 MVC模式:MVC(Model.View.Controller)是软件开发过程中比较流行的设计思想.旨在分离模型.控制.师徒.是一种分层思想的体现. Model2简介Java Web ...

  4. Memcached 之 .NET(C#)实例分析

    一:Memcached的安装 step1. 下载memcache(http://jehiah.cz/projects/memcached-win32)的windows稳定版(这里我下载了memcach ...

  5. 【BZOJ3622】已经没有什么好害怕的了 容斥+DP

    [BZOJ3622]已经没有什么好害怕的了 Description Input Output Sample Input 4 2 5 35 15 45 40 20 10 30 Sample Output ...

  6. [算法][LeetCode]Spiral Matrix——螺旋矩阵

    题目要求 Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spir ...

  7. css 更改input radio checkbox的样式

    html <label> <input type="checkbox" class="colored-blue"> <span c ...

  8. Chrome浏览器断点调试无效的问题

    问题是这样的,在使用chrome浏览器调试JavaScript的时候,突然设置的断点失效了,怎么弄都没有效果. 折腾了半天,尝试了各种方法就是没有用. 解决:重启一下chrome浏览器就好了,这似乎是 ...

  9. 160401、关于cronExpression的介绍

    关于cronExpression的介绍:   每一个字段都有一套可以指定有效值,如 Seconds (秒):可以用数字0-59 表示, Minutes(分)          :可以用数字0-59 表 ...

  10. git 学习(2)--恢复版本

    查看修改历史记录 $ git log commit fba77877d316436c1b774b8933380ebcac668040 Author: keith <ustbfxx@163.com ...