CodeForces - 848A From Y to Y(构造)
2017-09-04 20:54
302 查看
From Y to Y
题目链接:From Y to Y题意:
对于字符串s和字符c,f(s,c)表示c在s中出现的次数,若将c合并到s中,则花费f(s,c)。要求一个字符串,使得合并后的最小花费恰好等于k
思路:
可以发现,对于只有一个字符的字符串s,若它的长度为n,则花费为0+1+2+…+n-1
因此我们依次添加不同的字符凑到k即可
代码:
#include<stdio.h> int main() { int k; scanf("%d",&k); if(!k) { puts("a"); return 0; } for(int i=0;i<26;++i) { int x=1; while(k>=(x*(x-1)/2)) ++x; k-=(x-2)*(x-1)/2; for(int j=1;j<x;++j) printf("%c",'a'+i); if(!k) return 0; } }
相关文章推荐
- Codeforces 388B Fox and Minimal path(构造最短路条数为N的图)
- Codeforces 410C.Team[构造]
- codeforces 486C Palindrome Transformation 贪心求构造回文
- CodeForces 128D Numbers 构造
- Codeforces 417C Football(构造)
- codeforces-544B-Sea and Islands【构造】
- Codeforces 639B——Bear and Forgotten Tree 3——————【构造、树】
- CodeForces - 848A From Y to Y(构造)
- Codeforces 362D Fools and Foolproof Roads 构造题
- 【瞎搞】 Codeforces 460D Little Victor and Set 位运算构造
- CodeForces 669D 构造
- 【Codeforces 747B Mammoth's Genome Decoding】+ 构造
- codeforces 460D Little Victor and Set(构造、枚举)
- CodeForces 550E Brackets in Implications(构造)
- Codeforces 483C Diverse Permutation【思维构造】
- CodeForces 459 C.Pashmak and Buses(构造)
- CodeForces 185A. Plant(矩阵快速幂) 构造
- CodeForces 673D - Bear and Two Paths(构造)
- CodeForces 550D Regular Bridge(构造)
- CodeForces 658C Bear and Forgotten Tree 3(构造)