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 ...
随机推荐
- 使用 HTML5 的 IndexedDB API
1. [代码]判断是否支持 IndexedDB var indexedDB = window.indexedDB || window.webkitIndexedDB || window.moz ...
- codeforces 706D D. Vasiliy's Multiset(trie树)
题目链接: D. Vasiliy's Multiset time limit per test 4 seconds memory limit per test 256 megabytes input ...
- leetcode 66. Plus One(高精度加法)
Given a non-negative number represented as an array of digits, plus one to the number. The digits ar ...
- 多线程mtr-代码
#!/bin/env python # -*- coding: utf-8 -*- # @Date : 2015-09-06 11:30:48 # @Author : Your Name (you@e ...
- P2764 [网络流24题]最小路径覆盖问题[最大流]
地址 这题有个转化,求最少的链覆盖→即求最少联通块. 设联通块个数$x$个,选的边数$y$,点数$n$个 那么有 $y=n-x$ 即 $x=n-y$ 而n是不变的,目标就是在保证每个点入度.出度 ...
- 【Python】numpy 数组拼接、分割
摘自https://docs.scipy.org 1.The Basics 1.1 numpy 数组基础 NumPy’s array class is called ndarray. ndarray. ...
- 【算法模板】Binary Search 二分查找
模板:(通用模板,推荐) 给定一个排序的整数数组(升序)和一个要查找的整数target,用O(logn)的时间查找到target第一次出现的下标(从0开始),如果target不存在于数组中,返回-1. ...
- 设计四个线程,其中两个线程每次对j加1,另外两个线程每次对j减1
public class ManyThreads2 { private int j = 0; public synchronized void inc() { j++; System.out.prin ...
- 对于makefile传递参数的一些问题
makefile变量说明: 1.总控Makefile中使用“-e”参数覆盖下一层Makefile中的变量. 2.父级Makefile向子级Makefile传送变量方式:export <varia ...
- Oracle字符串截断
字段.SUBSTR(string,start_position,[length]) 求子字符串,返回字符串解释:string 元字符串, start_position 开始位置(从0开始), leng ...