CodeForces - 848A From Y to Y(构造)
2017-09-04 20:54
513 查看
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 12E Start of the season 构造 一个n*n矩阵使得每行恰好有一个[0,n-1]且对称
- CodeForces 664 C.International Olympiad(构造)
- CodeForces-743C Vladik and fractions(构造)
- Codeforces 612E - Square Root of Permutation (置换+构造)
- CodeForces - 867B Save the problem! 构造
- Codeforces 605B 构造
- CodeForces - 848A From Y to Y(构造)
- Codeforces 303A Lucky Permutation Triple 【构造 思维】
- CodeForces - 622D Optimal Number Permutation 构造
- Codeforces 464A No to Palindromes!(构造)
- Codeforces 746D Green And Black Tea 构造
- [Codeforces - Gym100801H (NEERC)] Hash Code Hacker (字符串构造)
- Codeforces 584 C Marina and Vasya【构造+贪心】
- codeforces-148C-Terse princess【构造】
- codeforces 449C C. Jzzhu and Apples(数论+构造)
- Codeforces 388B Fox and Minimal path(构造)
- Codeforces 414A Mashmokh and Numbers(构造)
- Codeforces Round #209 (Div. 2) B && Codeforces 359 B(构造)
- CodeForces 66D 数学构造
- CodeForces 22C System Administrator 小水怡情 图论+构造