Codeforces Global Round 8 B. Codeforces Subsequences(构造)
题目链接:https://codeforces.com/contest/1368/problem/B
题意
构造最短的至少含有 $k$ 个 $codeforces$ 子序列的字符串。
题解
如下表:
| c | o | d | e | f | o | r | c | e | s | 子序列个数 | |
| 个数 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | $1^{10}$ |
| 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | $2^{10}$ | |
| 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | $3^{10}$ |
依次构造每个字符的个数即可。
证明
| c | o | d | e | f | o | r | c | e | s | 子序列个数 | |
| 个数 | 2 | 2 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | $4$ |
| 2 | 3 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | $6$ | |
| 2 | 2 | 2 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | $8$ |
向第一行的构造方案中再添加一个字符有第二、三行两种方式,显然第三行的方式子序列更多。
因为第二行增加的是 $2 \times 1^8$,第三行增加的是 $2^2 \times 1^7$,即每增加一个字符增加子序列个数的为其他字符个数的乘积,所以每个字符的个数一定会如上表依次增大。
代码
C++
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
string s = "codeforces";
int main() {
ll k; cin >> k;
vector<int> cnt(10, 1);
ll tot = 1;
for (int loop = 2; tot < k; loop++) {
for (int j = 0; j < 10; j++) {
if (tot < k) {
tot = tot / cnt[j] * loop;
cnt[j] = loop; //同cnt[j]++
}
}
}
for (int i = 0; i < 10; i++)
cout << string(cnt[i], s[i]);
}
Python3
from functools import reduce s = "codeforces"
a = [0] * 10
k = int(input())
p = 0 while reduce(lambda x, y : x * y, a) < k:
a[p % 10] += 1;
p += 1 for i in range(10):
print(s[i] * a[i], end = "")
Codeforces Global Round 8 B. Codeforces Subsequences(构造)的更多相关文章
- Codeforces Global Round 9 A. Sign Flipping (构造)
题意:有一个长度为\(n\)(odd)的序列,可以更改所有的数的正负,要求最少\(\frac{n-1}{2}\)个\(a_{i+1}-a_i\ge0\),并且要求最少\(\frac{n-1}{2}\) ...
- Codeforces Global Round 9 B. Neighbor Grid (构造,贪心)
题意:给一个\(n\)X\(m\)的矩阵,矩阵中某个数字\(k\)表示其四周恰好有\(k\)个不为0的数字,你可以使任意位置上的数字变大,如果操作后满足条件,输出新矩阵,否则输出NO. 题解:贪心,既 ...
- Codeforces Global Round 3
Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...
- CodeForces Global Round 1
CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...
- Codeforces Global Round 1 - D. Jongmah(动态规划)
Problem Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...
- Codeforces Global Round 2 题解
Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...
- Codeforces Global Round 1 (A-E题解)
Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...
- Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)
Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...
- 【手抖康复训练1 】Codeforces Global Round 6
[手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...
随机推荐
- es6 Array.from + new Set 去重复
// es6 set数据结构 生成一个数据集 里面的元素是唯一的 const items = new Set([1, 2, 3, 4, 5, 5, 5, 5]); // items 是个对象 item ...
- spring ioc踏出第一步
spring IOC(容器) AOP(面向切面编程) IOC容器:他的功能就是可以整合像 Structs2 .Hibernate.Mybatis: IOC:控制反转:所谓的控制就是控制资源的获取方法, ...
- 【Vue】Vue框架常用知识点 Vue的模板语法、计算属性与侦听器、条件渲染、列表渲染、Class与Style绑定介绍与基本的用法
Vue框架常用知识点 文章目录 Vue框架常用知识点 知识点解释 第一个vue应用 模板语法 计算属性与侦听器 条件渲染.列表渲染.Class与Style绑定 知识点解释 vue框架知识体系 [1]基 ...
- 【Oracle】instr()函数详解
1)instr()函数的格式 (俗称:字符查找函数) 格式一:instr( string1, string2 ) / instr(源字符串, 目标字符串) 格式二:instr( strin ...
- mount: /dev/sdxx already mounted or /xxxx busy解决方法
异常现象: 解决方法: 1. 輸入root的密碼,進入單用戶2. 重新掛載/目錄,使其變為可讀可寫 # mount –o rw,remount / 3. 修改/etc/fstab文件 ...
- 源代码增强的一点说明(souce code enhance )
souce code enhance 分为显式和隐式两种. 下面以显式创建为例子: 1.在ABAP编辑器中, 打开想要编辑的程序,切换到可编辑模式 2.在源代码中的指定位置右键,弹出菜单,选择 Enh ...
- springAOP的概述及使用
Spring AOP SpringAOP是Spring中非常重要的功能模块之一,该模块提供了面向切面编程,在事务处理,日志记录,安全控制等操作中广泛使用. SpringAOP的基本概念 AOP的概念 ...
- Graph Explore的使用介绍
我在Graph API开发中用的最多的测试工具就是Graph Explore,这个是微软开发的网页版的Graph API的测试工具,能满足我大部分需求. 访问网址是:Graph Explorer - ...
- ABP vNext 实现租户Id自动赋值插入
背景 在使用ABP vNext过程中,因为我们的用户体系庞大,所以一直与其他业务同时开发,在开发其他业务模块时,我们一直存在着误区:认为ABP vNext 自动处理了数据新增时的租户Id(Tenant ...
- 关于springboot2.X使用外部tomcat服务器进行部署的操作详细步骤
1.修改pom.xml文件(4个地方) ①<packaging>war</packaging>将其中的jar该为war ②<dependency> <grou ...