题目:

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 ;
}

最新文章

  1. iOS----- Crash 分析(文二)-崩溃日志组成
  2. CSS魔法堂:&quot;那不是bug,是你不懂我!&quot; by inline-block
  3. 安装numpy库
  4. SimpleAdapter的使用
  5. Spring 下载与安装以及spring 3.2.9 jar包详解
  6. Spring与Quartz的整合实现定时任务调度
  7. SQL中的日期时间函数
  8. Android SimpleAdapter源码详解
  9. 暴力求解——UVA 572(简单的dfs)
  10. 手势触摸定位(UIPanGestureRecognizer)
  11. Python 购物车----之用户部分
  12. asp.net core 教程(七)-异常处理、静态文件
  13. oracle中 sql%rowcount 用法
  14. js-clickNumCount.html
  15. npm cnpm +nodejs
  16. Quartz.NET 入门,带C#实例
  17. Java语法基础课 动手动脑
  18. 简单的分页小demo
  19. win7 php5.6 redis扩展
  20. cglib动态代理代码示例

热门文章

  1. MathType中输入不了汉字如何处理
  2. hdu 2809(状压dp)
  3. ios开发之 -- Swap file &quot;.Podfile.swp&quot; already exists!
  4. mac 10.9 dock在多屏幕间移动
  5. IOS内购支付服务器验证模式
  6. android基础----&gt;AccessibilityService的简单使用(一)
  7. JAVAWEB基础模块开发顺序与数据访问对象实现类步骤
  8. CodeForces 639 A
  9. CH5101 LCIS【线性dp】
  10. Pycharm取消默认的右击运行unittest方法