题目链接


给出字符串,统计子串(子串字母可以跳跃)是codeforces的数量。
本题要求,给出子串最少数量k,构造字符串s,要求字符串s包含的字母数量最少,输出这个最少的字符串s.


题目要求是至少有k个:我们一直想将k分解质因子转化为乘法原理qwq,但是k太大了qwq,贪心确实难啊!贪心题出的多了思维强度还是没跟上来


我们其实可以是一个位置一个位置的逐渐增加的


1
codeforces
有1个子串codeforces2
ccodeforces
有2个子串codeforces3
ccoodeforces
有2*2=4个子串codeforces
4>=34
ccoodeforces
有4个子串codeforces
4>=45
ccoodeforces
有2*2*2=8个子串ccooddeforces
8>=5

怎么证明这个做法是最优的呢?:就说均摊好像我也不会证明但是加法递增比乘法还小


#include <iostream>
#include <cstdio>
#include <stack>
#include <sstream>
#include <vector>
#include <map>
#include <cstring>
#include <deque>
#include <cmath>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <set>
#define mid ((l + r) >> 1)
#define Lson rt << 1, l , mid
#define Rson rt << 1|1, mid + 1, r
#define ms(a,al) memset(a,al,sizeof(a))
#define log2(a) log(a)/log(2)
#define _for(i,a,b) for( int i = (a); i < (b); ++i)
#define _rep(i,a,b) for( int i = (a); i <= (b); ++i)
#define rep_(i,a,b) for( int i = (a); i >= (b); -- i)
#define for_(i,a,b) for( int i = (a); i > (b); -- i)
#define lowbit(x) ((-x) & x)
#define IOS std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INF 0x3f3f3f3f
#define hash Hash
#define next Next
#define count Count
#define pb push_back
#define f first
#define s second
using namespace std;
const int N = 1e7+10, mod = 1e9 + 7;
const double eps = 1e-10;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
template<typename T> void read(T &x)
{x = 0;char ch = getchar();ll f = 1;while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
template<typename T, typename... Args> void read(T &first, Args& ... args)
{read(first);read(args...);
}
int l, n;
ll k;
char s[11] = "codeforces";
int a[11];
int main()
{for(int i = 0; i < 10; ++ i)a[i] = 1;read(k);while(1){ll sum = 1;for(int i = 0; i < 10; ++ i)sum *= a[i];if(sum >= k) break;a[l ++] ++;l %= 10;}for(int i = 0; i < 10; ++ i)for(int j = 1; j <= a[i]; ++ j)cout << s[i];return 0;
}

贪心 ---- Codeforces Global Round 8,B. Codeforces Subsequences[贪心,贪的乘法原理]相关推荐

  1. Codeforces Global Round 1 晕阙记

    Codeforces Global Round 1 晕阙记 我做这场比赛的时候晕得要死.做这三道题做太久了,rating涨不起来啊! A 如果愿意的话你可以看做是膜2意义下的运算,写快速幂等各种膜运算 ...

  2. Codeforces Global Round 3

    Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...

  3. codeforces global round 23

    constest :codeforces global round 23 contest time:2022.10.16 contest grade: 2800 contest rating chan ...

  4. Codeforces Global Round 14 F. Phoenix and Earthquake 思维 + 并查集

    传送门 文章目录 题意: 思路: 题意: 给你nnn个点,mmm条边,限制xxx,每个点都有沥青aia_iai​,定义合并两个点即两点之间有边且au+av≥xa_u+a_v\ge xau​+av​≥x ...

  5. Codeforces Global Round 1

    Codeforces Global Round 1 题解:The Editorial of the First Codeforces Global Round A:其实mod 2计算一下就行了 B:删 ...

  6. 【Codeforces Global Round 23】B. Rebellion

    Codeforces Global Round 23中B. Rebellion Codeforces比赛记录 文章目录 题目链接: 一.B. Rebellion 题目意思: 上思路: 总结 B. Re ...

  7. Codeforces Global Round 4-D. Prime Graph(伯特兰-切比雪夫定理)

    题目:Codeforces Global Round 4-D. Prime Graph 题意:给出n(顶点的个数),要求所得图满足: 1.无平行边和自环 2.边的总数是个质数 3.每个点的度(也就是点 ...

  8. Codeforces Global Round 12 D. Rating Compression 思维 + 贪心

    传送门 题意: 给一个长度为nnn的数组aaa,定义一个数组bbb,且bj=minj<=i<=j+k−1aib_j=min_{j<=i<=j+k-1}a_ibj​=minj&l ...

  9. Codeforces Beta Round #11 A. Increasing Sequence 贪心

    A. Increasing Sequence 题目连接: http://www.codeforces.com/contest/11/problem/A Description A sequence a ...

最新文章

  1. kalilinux安装搜狗输入法
  2. LaTeX入门最终集 :LaTeX格式的调整LaTeX中怎么打出数学公式LaTeX的各种上下标
  3. lstm原理_通俗易懂的方式介绍LSTMGRU(动图)
  4. 痛与快乐有一个代码是什么_养一只真大型犬的生活是什么样的?铲屎官:痛并快乐着!...
  5. java crs校验_AIX系统学习之-CRS安装后校验
  6. 华为手机设置页面黑色_华为手机里最危险的设置,学会这一招,手机还能再战三年...
  7. 微博办公李国庆:急招副总裁,提请股权激励,希望俞渝同意
  8. 图像直方图及均衡方法总结(二)自适应直方图均衡AHE,CLAHE
  9. 执行对象cocos2d-x 2.x action动作整理集合
  10. win7系统怎么设置sql服务器,win7系统怎么安装sqlserver2000软件(图文)
  11. linux freemind字体,解决 ubuntu 18.04 lts freemind 或freeplane 乱码口口的问题
  12. 云计算里的家校互联平台
  13. R实战 | Nomogram(诺莫图/列线图)及其Calibration校准曲线绘制
  14. slk文件转换器安卓版_【更新】手机QQ、微信语音读取转换工具【sik\amr格式转mp3】...
  15. opencv mat与cvmat, iplimage转换
  16. lego loam 安装过程与问题处理
  17. AutoCAD Civil 3D-曲面-曲面对象转换成AutoCAD三维实体
  18. 在ppt Excel world中 批量删除超链接
  19. 互联网全球性、开放性的特点
  20. 可编程DDC控制器的实现 (1)

热门文章

  1. 计算机操作系统第四版习题答案 第一章简答题
  2. 计算机视觉方向简介:深度图补全
  3. 目标检测中的Tricks
  4. 机器人是如何规划路径的?动画演示一下吧
  5. OpenCV中直方图反向投影算法详解与实现
  6. 视频程式化的基于帧差异的时间损失
  7. hadoop思维导图
  8. 4.1ASP.NET Core请求过程「深入浅出ASP.NET Core系列」
  9. HDFS-Shell
  10. 浅尝key-value数据库(三)——MongoDB的分布式