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题秒出思 ...
随机推荐
- Spring Boot 2.0 的配置绑定类Bindable居然如此强大
1. 前言 在开发Spring Boot应用时会用到根据条件来向Spring IoC容器注入Bean.比如配置文件存在了某个配置属性才注入Bean : 图中红色的部分是说,只有ali.pay.v1.a ...
- spring cloud gateway 日志打印
从api请求中获取访问的具体信息,是一个很常见的功能,这几天在研究springcloud,使用到了其中的gateway,刚好将研究的过程结果都记录下来 0. Version <parent> ...
- 你都用过SpringCloud的哪些组件,它们的原理是什么?
前言 看到文章的题目了吗?就是这么抽象和笼统的一个问题,确实是我面试中真实被问到的,某共享货车平台的真实面试问题. SpringCloud确实是用过,但是那是三四年前了,那个时候SpringCloud ...
- Kaggle泰坦尼克-Python(建模完整流程,小白学习用)
参考Kernels里面评论较高的一篇文章,整理作者解决整个问题的过程,梳理该篇是用以了解到整个完整的建模过程,如何思考问题,处理问题,过程中又为何下那样或者这样的结论等! 最后得分并不是特别高,只是到 ...
- awk -v参数
-v var=val --assign var=val Assign the value val to the variable var, before execution of the progra ...
- 【Oracle】查询锁的相关SQL
--查看有锁的进程 select t2.username,t2.sid,t2.serial#,t2.logon_time,t2.state from v$locked_object t1,v$sess ...
- Ribbon负载均衡服务调用
1.在听周阳老师讲解时,使用Ribbon核心组件IRule时是这样用的: ribbon版本 : 自定义配置类不能放在@ComponentScan所扫描的当前包下以及子包下,项目结构如下 MySelfR ...
- nodejs内网穿透
说明 本地服务注册,基于子域名->端口映射.公网测试请开启二级或三级域名泛解析 无心跳保活.无多线程并发处理 服务器端 请求ID基于全局变量,不支持PM2多进程开服务端.(多开请修改uid函数, ...
- PAT Advanced 1004 Counting Leaves
题目与翻译 1004 Counting Leaves 数树叶 (30分) A family hierarchy is usually presented by a pedigree tree. You ...
- Percona Toolkit工具使用
Percona Toolkit简称pt工具-PT-Tools,是Percona公司开发用于管理MySQL的工具,功能包括检查主从复制的数据一致性.检查重复索引.定位IO占用高的表文件.在线DDL等 下 ...