【链接】点击打开链接


【题意】


让你构造一个大小最多为10W的字符multiset.
你进行n-1次操作;
每次操作,从set中取出两个字符串,一开始单个字符被认为是字符串.
然后把它们连接在一起。
(那两个字符串扔掉)
然后花费的计算方式如题目那个式子。
要求你构造出来的multiset进行n-1次操作后,总花费恰好为k.

【题解】


相同的字符假如有x个,则最后答案会递增x*(x-1)/2.
因为相同的字符t全都按顺序合并在一起是最优的。(贪心!);
(其实观察一下样例就知道了);
(然后其他字母就不会和这个t有关系了,不会造成影响)
然后对于'a'..'z'
每个都找到最大的i;
使得i*(i-1)/2<=k;
然后k-=i*(i-1)/2
可以保证,最后一定能让k恰好变成0的,也即有解.
(因为i*(i-1)/2可以为1)
每找一次最大的i之后,剩下的k都越来越小。最坏的情况,26个字母完全能承受。
把每个字母都输出对应的i次就好了

【错的次数】


0

【反思】


没吸取教训,先去hack人了.
下次做完A,B,C再cha人!

【代码】

/*

*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <cstdlib>
#include <cmath>
#include <bitset>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb emplace_back
#define fi first
#define se second
#define ld long double
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define rf(x) scnaf("%lf",&x)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)
#define sz(x) ((int) x.size())
#define ld long double typedef pair<int,int> pii;
typedef pair<LL,LL> pll; //mt19937 myrand(time(0));
//int get_rand(int n){return myrand()%n + 1;}
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e5; int k; int main(){
//Open();
//Close();
while (~ri(k)){
for (char i = 'a';i <= 'z';i++){
int j = 1;
for (j = 1;j*(j-1)/2 <= k;j++);
j--;
rep1(k,1,j) putchar(i);
k-=j*(j-1)/2;
if (k==0)break;
}
puts("");
}
return 0;
}

【Codeforces Round #431 (Div. 2) C】From Y to Y的更多相关文章

  1. 【Codeforces Round #431 (Div. 2) B】 Tell Your World

    [链接]点击打开链接 [题意] n个点,x从左到右严格递增的顺序给出 让你划两条平行的,且没有相同点的直线; 使得它们俩各自最少穿过一个点. 且它们俩穿过了所有的点. [题解] 枚举第一个点和哪个点组 ...

  2. 【Codeforces Round #431 (Div. 2) A】Odds and Ends

    [链接]点击打开链接 [题意] 让你把一个数组分成奇数个部分. 且每个部分的长度都是奇数. [题解] 很简单的脑洞题. 开头和结尾一定要为奇数,然后 n为奇数的话,就选整个数组咯. n为偶数的话,不能 ...

  3. 【Codeforces Round #431 (Div. 1) B】

    [链接]h在这里写链接 [题意] 场上有 n 个点,它们分别向上与向右在不同时刻开始运动,相遇则改变移动方向,求最终这些点到达的坐标. [题解] 先把每个点的坐标都往它本该移动的方向相反的方向退ti个 ...

  4. 【Codeforces Round 431 (Div. 2) A B C D E五个题】

    先给出比赛地址啦,感觉这场比赛思维考察非常灵活而美妙. A. Odds and Ends ·述大意:      输入n(n<=100)表示长度为n的序列,接下来输入这个序列.询问是否可以将序列划 ...

  5. 【Codeforces Round #428 (Div. 2) C】Journey

    [Link]:http://codeforces.com/contest/839/problem/C [Description] 给一棵树,每当你到一个点x的时候,你进入x的另外一每一个出度的概率都是 ...

  6. 【Codeforces Round #460 (Div. 2) D】Substring

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果有环 ->直接输出-1 (拓扑排序如果存在某个点没有入过队列,说明有环->即入队的节点个数不等于n 否则. 说明可以 ...

  7. 【Codeforces Round #459 (Div. 2) B】 Radio Station

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用map模拟一下映射就好了. [代码] #include <bits/stdc++.h> using namespace ...

  8. 【Codeforces Round #451 (Div. 2) B】Proper Nutrition

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 可以直接一层循环枚举. 也可以像我这样用一个数组来存y*b有哪些. 当然.感觉这样做写麻烦了.. [代码] /* 1.Shoud i ...

  9. 【Codeforces Round #450 (Div. 2) A】Find Extra One

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟. 看看Y左边或右边的点个数是否<=1 [代码] #include <bits/stdc++.h> using ...

随机推荐

  1. 利用Python网络爬虫抓取微信好友的所在省位和城市分布及其可视化

    前几天给大家分享了如何利用Python网络爬虫抓取微信好友数量以及微信好友的男女比例,感兴趣的小伙伴可以点击链接进行查看.今天小编给大家介绍如何利用Python网络爬虫抓取微信好友的省位和城市,并且将 ...

  2. python数据处理技巧一

    字符串赋值(传参)技巧 Python中一般的字符串赋值的方式如下: variable = "Test" print "I just [%s] unit"%var ...

  3. 喜马拉雅FM

    import requestsimport jsonstart_url ='https://www.ximalaya.com/revision/play/album?albumId=3595841&a ...

  4. XCode6报数组越界错误的问题

    今天碰到一个非常奇葩的问题, 调试了半天: 错误:"index 0 beyond bounds for empty array",  意思就是说数据源数组为nil, 所以你调用直接 ...

  5. UVA 12508 - Triangles in the Grid(计数问题)

    12508 - Triangles in the Grid 题目链接 题意:给定一个n∗m格子的矩阵,然后给定A,B.问能找到几个面积在A到B之间的三角形. 思路:枚举每一个子矩阵,然后求[0,A]的 ...

  6. BZOJ 1355 KMP中next数组的应用

    思路: 我们知道 next[i]是失配的i下一步要去哪儿 next[n]就是失配的n要去哪儿 n-next[n]就是答案(即最短周期)啦 //By SiriusRen #include <cst ...

  7. 基于 Web 的 Go 语言 IDE - Wide 1.1.0 发布!

    发布 1.1.0 这个版本改进了很多细节,已经完全可以用于正式项目的开发 同时我们上线了 Wide 在线服务 到目前,我们提供了 Wide 和 Solo 两个在线服务,详情请看这里. Wide 是什么 ...

  8. ToString DateTime 操作

    来源:网络 字符型转换为字符串// C 货币 2.5.ToString("C"); // ¥2.50 // D 10进制数 25.ToString("D5"); ...

  9. ELK+KAFKA安装部署指南

    一.ELK 背景 通常,日志被分散的储存不同的设备上.如果你管理数十上百台服务器,你还在使用依次登录每台机器的传统方法查阅日志.这样是不是感觉很繁琐和效率低下.当务之急我们使用集中化的日志管理,例如: ...

  10. Method and apparatus for transitioning between instruction sets in a processor

    A data processor (104) is described. The data processor (104) is capable of decoding and executing a ...