博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #431 (Div. 1)
阅读量:6187 次
发布时间:2019-06-21

本文共 2722 字,大约阅读时间需要 9 分钟。

A. 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.

 

 

/** @Author: LyuC* @Date:   2017-09-03 15:10:19* @Last Modified by:   LyuC* @Last Modified time: 2017-09-03 16:56:48*//* 题意:初始的时候一个集合内有n个元素(a-z的字符),你可以进行这样的操作,每次取出集合内的    两个元素删除,然后将这两个元素连起来作为一个元素放到集合内,此次操作的代价:        f(s,c)*f(t,c),f(s,c)函数定义为,a-z每个字符在s中出现的次数的加和,现在给你一个    代价k,让你构造出满足要求的字符串 思路:n个相同的字符,构造的代价是n*(n-1)/2,然后这样就可以凑出k*/#include 
using namespace std;int n;string s;int pos;int i;inline void init(){ s=""; pos=0;}int main(){ // freopen("in.txt","r",stdin); init(); scanf("%d",&n); if(n==0){ puts("a"); return 0; } while(n>0){ i=0; while(++i){ if(i*(i-1)/2>n){ break; } } i--; n-=i*(i-1)/2; while(i--){ s+=pos%26+'a'; } pos++; } cout<
<

 

转载于:https://www.cnblogs.com/wuwangchuxin0924/p/7469994.html

你可能感兴趣的文章
关于qstring转char乱码问题。
查看>>
Kurento源码安装(Ubuntu 14.04和 Ubuntu 16.04)
查看>>
Redis在Php项目中的实际应用场景
查看>>
面试题(1)
查看>>
【第3章】数据库的基本操作
查看>>
MySQL备份原理详解
查看>>
分别查找主机占用CPU和占用内存最大的进程,要求能查出进程PID,启动目录,启动命令,占用文件描述符数量,占用端口...
查看>>
android 清除缓存cache
查看>>
powerdesigner连接数据库的问题
查看>>
git-git基本使用
查看>>
Spring Cloud Stream如何处理消息重复消费?
查看>>
CSS3 Media Queries 详解
查看>>
JavaLib | 使用AOP帮你记录日志
查看>>
Hibernate与 MyBatis的比较
查看>>
DNS劫持原理与实现
查看>>
努力学习
查看>>
乐观锁和悲观锁初步认识
查看>>
MFC中的几个常用类——CWinApp
查看>>
overflow、display、visibility的区别?
查看>>
架构学习(二)知识脑图
查看>>