Codeforces Round #431 (Div. 2) C
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.
The first and only line of input contains a non-negative integer k (0 ≤ k ≤ 100 000) — the required minimum cost.
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.
12
abababab
3
codeforces
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 搞定
#include<bits/stdc++.h>
using namespace std;
double x[];
set<double>Se;
double ans;
int main(){
int n;
cin>>n;
string s="";
if(n==){
cout<<"a"<<endl;
}else{
char c='a';
while(n){
int sum=;
int i=;
for(i=;sum<=n;i++){
sum+=i;
} n-=(sum-i+);
for(int j=;j<i-;j++){
s+=c;
}
c++;
}
cout<<s<<endl;
}
return ;
}
Codeforces Round #431 (Div. 2) C的更多相关文章
- 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 ...
- Codeforces Round #431 (Div. 2) C. From Y to Y
题目: C. From Y to Y time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 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 ...
- 【Codeforces Round #431 (Div. 1) D.Shake It!】
·最小割和组合数放在了一起,产生了这道题目. 英文题,述大意: 一张初始化为仅有一个起点0,一个终点1和一条边的图.输入n,m表示n次操作(1<=n,m<=50),每次操作是任选一 ...
- 【Codeforces Round 431 (Div. 2) A B C D E五个题】
先给出比赛地址啦,感觉这场比赛思维考察非常灵活而美妙. A. Odds and Ends ·述大意: 输入n(n<=100)表示长度为n的序列,接下来输入这个序列.询问是否可以将序列划 ...
- Codeforces Round #431 (Div. 2) B. Tell Your World
B. Tell Your World time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 【推导】【分类讨论】Codeforces Round #431 (Div. 1) B. Rooter's Song
给你一个这样的图,那些点是舞者,他们每个人会在原地待ti时间之后,以每秒1m的速度向前移动,到边界以后停止.只不过有时候会碰撞,碰撞之后的转向是这样哒: 让你输出每个人的停止位置坐标. ①将x轴上初始 ...
- 【推导】【贪心】Codeforces Round #431 (Div. 1) A. From Y to Y
题意:让你构造一个只包含小写字母的可重集,每次可以取两个元素,将它们合并,合并的代价是这两个元素各自的从‘a’到‘z’出现的次数之积的和. 给你K,你构造的可重集必须满足将所有元素合而为一以后,所消耗 ...
- Codeforces Round #431 (Div. 2) B
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a c ...
随机推荐
- BZOJ 3410 [Usaco2009 Dec]Selfish Grazing 自私的食草者:贪心【最多线段覆盖】
题目链接:http://begin.lydsy.com/JudgeOnline/problem.php?id=1324 题意: 给你n个区间,问你最多能选择多少个区间使得它们不相互覆盖. 题解: RQ ...
- 勤于思考:Objective-C特性的扩展
赋值 assign:直接赋值.默认 @interface Car : NSObject { NSString *_name; } @property (assign,nonatomic) NSStri ...
- ACM学习历程——POJ 1700 Crossing River(贪心)
Description A group of N people wishes to go across a river with only one boat, which can at most ca ...
- Python定时任务-schedule vs. Celery vs. APScheduler
在Python开发过程中我们经常需要执行定时任务,而此类任务我们通常有如下选项: 自己造轮子 使用schedule库 使用Celery定时任务 使用APScheduler 自己造轮子实现,最大的优势就 ...
- BZOJ3524:[POI2014]Couriers
浅谈主席树:https://www.cnblogs.com/AKMer/p/9956734.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem.p ...
- java计算两个时间相差(天、小时、分钟、秒)
public static Long dateDiff(String startTime, String endTime, String format, String str) { // 按照传入的格 ...
- POJ 3258 最小值最大化 二分搜索
题意:牛要到河对岸,在与河岸垂直的一条线上,河中有N块石头,给定河岸宽度L,以及每一块石头离牛所在河岸的距离, 现在去掉M块石头,要求去掉M块石头后,剩下的石头之间以及石头与河岸的最小距离的最大值. ...
- python UnicodeEncodeError: 'ascii' codec can't encode characters 解决办法
程序直接运行没有问题,一旦用nohup python test.py 执行遇中文就报python UnicodeEncodeError错误: 最终测试出的解决方法为,在开头添加红色的三句: #!/us ...
- UGUI ScrollRect滑动居中CenterOnChild实现
NGUI有一个UICenterOnChild脚本,可以轻松实现ScrollView中拖动子物体后保持一个子物体位于中心位置.然而UGUI就没这么方便了,官方并没有类似功能的脚本.网上找到一些运行效果都 ...
- YOLO3训练widerface数据集
因为YOLO3速度精度都很棒,所以想训练一下人脸模型,废话不多,进入正题 1写所有的配置文件 1.1 YOLO3-face.cfg 个人感觉YOLO的配置文件骑士和caffe差不多 在cfg/YOLO ...