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 ...
随机推荐
- mybatis新增账号并且返回主键id
<!--新增账号和权限的关联关系--><insert id="save" useGeneratedKeys="true" keyPropert ...
- vue create is a Vue CLI 3 only command and you are using Vue CLI 2.9.6. You
这是因为你安装的是2.9的版本用了3.0的命令 解决方法:1.用2.9的命令初始化项目 vue init webpack my-project 2.卸载2.9升级到3.0
- 通过Rainbond的团队管理去管理已有的组织架构
针对于多团队管理我先列举几个小问题,看看大家有没有共鸣,我们在刚刚接触并使用Rainbond的时候,仅仅创建一个团队,里面创建一大堆应用,看起来特别乱,进行管理的时候呢,也会非常麻烦,尤其是当团队需要 ...
- vue项目中使用 SheetJS / js-xlsx 导出文件
1. npm install xlsx 2. 在App.vue 中引入xlsx import * as XLSX from 'xlsx'; // 数据导出导入所需要的依赖 3. 使用xlsx 3 ...
- ARC128D
考虑我们直接\(dp\). 那么需要快速的求出一段是否可以被消掉只剩两端. 我们可以考虑反过来做的. 我们知道如果全为\(abab\)型或者\(aa\)型则无法消掉 那么我们要前缀和,以及遇到\(aa ...
- [NOI Online #3 提高组] 魔法值
现在只会\(O(qn^3log)\)的\(40pts\)做法,鸽了. 反正就是预处理之后,去掉一个\(n\). 我预处理了,没去\(n\),hhhh,成功减少了一半的常数.
- Atcoder Grand Contest 032 E - Modulo Pairing(乱搞+二分)
Atcoder 题面传送门 & 洛谷题面传送门 神仙调整+乱搞题. 首先某些人(including me)一看到最大值最小就二分答案,事实上二分答案对这题正解没有任何启发. 首先将 \(a_i ...
- 【R】爬虫案例
爬取豆瓣相册 library(RCurl) library(XML) myHttpheader <- c("User-Agent"="Mozilla/5.0 (Wi ...
- windows和linux文本的编码格式不一样所出的错
windows下编写的python脚本上传的linux下执行会出现错误: usr/bin/python^M: bad interpreter: No such file or directory 原因 ...
- Linux—linux 查看一个文件有多少M
ls -l --block-size=M #就把目录下的所有文件按M单位呈现