Codeforces 849 C. From Y to Y (技巧)
来源:互联网 发布:js幻灯片切换效果代码 编辑:程序博客网 时间:2024/06/04 19:25
Description
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
∑c∈{′a′,′b′,...,′z′}f(s,c)×f(t,c) , wheref(s, c) denotes the number of times character c appears 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
Examples output
abababab
题意
给定一个代价
思路
分析可知,不论我们挑选哪两个元素合并最终结果都是一样的。
且每一次合并的贡献只和相同字母的个数有关。
例如:
因此,最终的代价
AC 代码
#include<bits/stdc++.h>using namespace std;const int maxn = 1e5+10;int cnt[maxn];void init(){ for(int i=1; i<=10000; i++) cnt[i]=i*(i-1)/2;}void solve(int n){ if(!n) puts("ab"); else { int tot=0; while(n) { int i=1; while(n>=cnt[i])++i; --i; n-=cnt[i]; while(i--) printf("%c",tot+'a'); tot++; } putchar('\n'); }}int main(){ init(); int n; while(cin>>n) solve(n);}
- Codeforces 849 C. From Y to Y (技巧)
- Codeforces 849 C From Y to Y
- CodeForces #431 Div. 2 849C From Y to Y 贪心 技巧题
- Codeforces 849C From Y to Y【思维】
- Codeforces 849 C. From Y to Y 结论题
- Codeforces From Y to Y
- C. From Y to Y
- Codeforces Round #431 (Div. 2) C. From Y to Y(补题)
- Codeforces Round #431 (Div. 2) From Y to Y
- codeforces 848A From Y to Y(思维)
- Codeforces848A-From Y to Y
- Codeforces849C From Y to Y
- Codeforces Round #431 (Div. 2) A、Odds and Ends B、Tell Your World C、From Y to Y
- CF848A From Y to Y【思路】
- codeforce 848A From Y to Y
- Codeforces Round #431 (Div. 2) 848A From Y to Y(思维)
- CF 848 A. From Y to Y【模拟】
- Convert from type X to type Y
- An Easy Problem
- Spark程序执行过程中遇到的线程安全问题及解决办法
- MVC 开发模式
- Java 网络编程
- Java 输入多行字符串或者多个int数值
- Codeforces 849 C. From Y to Y (技巧)
- SIGUSR1信号程序退出
- 2017面向对象程序设计(Java)第二周学习总结
- WAMP+PhpStorm配置,post提交获取不到值
- linux数据库编码问题解决
- Java开发环境搭建(windows版、史上最详细版)
- FastDFS安装配置
- 浅谈MVC、MVP、MVVM架构模式的区别和联系
- 【Redis源码剖析】