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 ...
随机推荐
- 单页导航菜单视觉设计HTML模板
单页导航菜单视觉设计HTML模板,视觉,企业,html,单页,单页导航菜单视觉设计HTML模板是一款磨砂背景的大气时尚HTML设计网页模板 http://www.huiyi8.com/moban/
- flash滑杆控制图片横向滚动
flash滑杆控制图片横向滚动是一款FLASH动画图片左右滚动素材,滑杆控制滚动,效果很酷,带FLASH源文件. 下载:http://www.huiyi8.com/sc/9452.html
- html5--1.7超链接上
html5--1.7超链接上 一.超链接的5种形式 <!DOCTYPE html> <html lang="en"> <head> <me ...
- LoadRunner中的函数
函数是LoadRunner提供给性能测试工程师的利器,有了它,性能测试工程师可以对脚本进行更为自由的开发,更适应实际测试的需求,进一步扩展脚本的功能. LoadRunner函数的格式: 返回值 函数 ...
- 分布式锁的实现方式——ACID数据库、缓存或者是zk
针对分布式锁的实现,目前比较常用的有以下几种方案: 基于数据库实现分布式锁 基于缓存(redis,memcached,tair)实现分布式锁 基于Zookeeper实现分布式锁 在分析这几种实现方案之 ...
- Wireshark 的使用 —— 过滤器(filter)
1. 基本 ip 地址: 目的IP:ip.dst==192.168.101.8,源ip:ip.src==1.1.1.1 不区分源和目的:ip.addr == 192.168.101.8: 端口过滤: ...
- xxx referenced from: xxx in xxx.o
情形一:可能是有一些源码文件没有加入工程所导致的,找到相应的.h和.m文件,将其add进入项目工程即可解决这种问题. 情形二:也有可能是某些framework没有加入项目中, 示例: Undefi ...
- ACM学习历程—HDU4725 The Shortest Path in Nya Graph(SPFA && 优先队列)
Description This is a very easy problem, your task is just calculate el camino mas corto en un grafi ...
- django-crontab 定时执行任务方法
需求 每天请求一封邮件,并读取该邮件 这个其实可以使用linux 自带了crontab实现,但是毕竟是django 开发.想着不知道有没有方法可以从django 中实现. 简单搜索了下,这方面的方法确 ...
- mysql数据库---编码格式基本操作
1.查看数据库编码格式 mysql> show variables like 'character_set_database'; 2.查看数据表的编码格式 mysql> show crea ...