CF721B Passwords 题解
Content
有一天,小 V 突然忘记了他在 Codehorses 的网站上的密码。但是他有所有网站上的 \(n\) 个密码 \(\{s_i\}_{i=1}^n\),所以他开始一个一个试。他会先从长度最小的密码开始试,如果有多个长度相等的密码就等概率随机选一个,并且他不会再去试已经试过的密码。输入密码需要 \(1\) 秒,如果连续输错 \(k\) 次密码就需要再等 \(5\) 秒才能重新开始试。已知他的密码是一个字符串 \(t\)。求最好情况和最坏情况下他试密码需要的时间。
数据范围:\(1\leqslant n,k\leqslant 100,0\leqslant |s_i|,|t|\leqslant 100\)。
Solution
我们可以开个桶存储一下所有的 \(|s_i|\),然后利用桶统计出所有长度 \(<|t|\) 的字符串个数,加进答案里面去,设此时答案为 \(ans\),那么这时,最好情况的话就只需要再试一次密码,最坏的情况就需要试所有 \(n\) 个密码中长度为 \(|t|\) 的密码。注意需要考虑连续输错需要加时的情况。
Code
int n, k, a[107];
string s[107], t;
int main() {
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; ++i) {
cin >> s[i];
int len = s[i].size();
a[len]++;
}
cin >> t; int lent = t.size(), ans = 0;
for(int i = 1; i < lent; ++i) ans += a[i];
printf("%d %d", (ans + 1) + (ans + 1) / k * 5 - (!((ans + 1) % k) ? 5 : 0), (ans + a[lent]) + (ans + a[lent]) / k * 5 - (!((ans + a[lent]) % k) ? 5 : 0));
return 0;
}
CF721B Passwords 题解的更多相关文章
- Codeforces Round #374 (Div. 2) B. Passwords 贪心
B. Passwords 题目连接: http://codeforces.com/contest/721/problem/B Description Vanya is managed to enter ...
- Codeforces Round #374 (Div. 2) B. Passwords —— 基础题
题目链接:http://codeforces.com/contest/721/problem/B B. Passwords time limit per test 2 seconds memory l ...
- 【37.21%】【codeforces 721B】Passwords
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces Round #603 (Div. 2) D. Secret Passwords 并查集
D. Secret Passwords One unknown hacker wants to get the admin's password of AtForces testing system, ...
- Codeforces 1292C Xenon's Attack on the Gangs 题解
题目 On another floor of the A.R.C. Markland-N, the young man Simon "Xenon" Jackson, takes a ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
随机推荐
- 使用 vue-property-decorator 用法总结
Vue + TypeScript 使用 vue-property-decorator 用法总结 简介 要使vue支持ts写法,我们需要用到vue-property-decorator,这个组件完全依赖 ...
- MYSQL5.8----M3
333333333333333333333333333 mysql> DESC user; +----------+---------------------+------+-----+---- ...
- perl中tr的用法(转载)
转载:http://blog.sina.com.cn/s/blog_4a0824490101hncz.html (1)/c表示把匹配不上的字符进行替换. $temp="AAAABCDEF&q ...
- FFmpeg笔记:使用MSVC工具链编译Windows版本静态库、动态库
2019年3月开始,为了将音视频编解码功能集成到Cocos2d-x中,开始接触到FFmpeg: 当时开发环境还在Mac下,编译FFmpeg相比现在用Windows平台要方便的多: 最近,公司内部有个U ...
- 我可以减肥失败,但我的 Docker 镜像一定要瘦身成功!
作者|徐伟 来源|尔达 Erda 公众号 简介 容器镜像类似于虚拟机镜像,封装了程序的运行环境,保证了运行环境的一致性,使得我们可以一次创建任意场景部署运行.镜像构建的方式有两种,一种是通过 do ...
- web自动化,selenium环境配置
1,首先我们需要在python编译器中添加selenium插件,我用的是pycharm 点击下方的Terminal,然后在命令行输入: pip install selenium 也可以在设置里面手动添 ...
- accommodate ~ ache
accommodate The accommodation reflex [反射] (or accommodation-convergence [会聚] reflex) is a reflex act ...
- nextcloud搭建私有云盘
一.基础环境准备 1.安装一台centos7的linux服务器. # 系统初始化 # 如果时区不对,请修改时区 #mv /etc/localtime /etc/localtime_bak #ln -s ...
- flink---实时项目----day03---1.练习讲解(全局参数,数据以parquet格式写入hdfs中) 2 异步查询 3 BroadcastState
1 练习讲解(此处自己没跑通,以后debug) 题目见flink---实时项目---day02 kafka中的数据,见day02的文档 GeoUtils package cn._51doit.flin ...
- OC-copy,单例
总结 编号 主题 内容 一 NSFileManager NSFileManager介绍/用法(常见的判断)/文件访问/文件操作 二 集合对象的内存管理 集合对象的内存管理/内存管理总结 三 *copy ...