CodeForces - 848A From Y to Y(构造)
2017-09-04 20:54
267 查看
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 550D - Regular Bridge(构造)
- Codeforces 417C Football(构造)
- CodeForces 417E (构造)
- Codeforces 710C_Magic Odd Square(构造)
- CodeForces 612e Square Root of Permutation(置换+构造)
- Codeforces 362D Fools and Foolproof Roads 构造题
- Codeforces 841D Leha and another game about graph 构造
- CodeForces 873D Merge Sort 构造 分治
- 【打CF,学算法——二星级】Codeforces 584C Marina and Vasya (简单构造)
- CodeForces - 848A From Y to Y(构造)
- codeforces 460D Little Victor and Set(构造)
- Codeforces 550D —— Regular Bridge——————【构造】
- codeforces 460D Little Victor and Set(构造、枚举)
- Codeforces 678 D. Iterated Linear Function(构造矩阵)
- 【Codeforces 746D Green and Black Tea】+ 构造
- Codeforces 891B Gluttony 构造
- Codeforces Round #209 (Div. 2) B && Codeforces 359 B(构造)
- Codeforces 765D Artsem and Saunders 【构造】
- CodeForces 66D 数学构造
- CodeForces 21C Stripe 2 构造题