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 ...
随机推荐
- 【PS】证件照转换背景色
证件照转换背景色 2019-07-14 12:18:49 by冲冲 1. 需求 自由切换证件照的背景颜色(白底.蓝底.红底...) 2. 步骤 ① 双击 图层锁 解锁,弹出的"新建图层0 ...
- Go语言程序结构之变量
初识Go语言之变量 var声明创建一个具体类型的变量,然后给它附加一个名字,设置他的初始值,这种声明都是一个通用的形式: var name type = expression 在实际的开发中,为了方便 ...
- git新手配置(ios环境)
ios环境,初步了解git是个什么东西,使用过svn相关软件最佳,否则可以先补一下git的相关概念和用处,相关教程:https://www.liaoxuefeng.com/wiki/896043488 ...
- Python+selenium之弹窗
- 柯基数据通过Rainbond完成云原生改造,实现离线持续交付客户
1.关于柯基数据 南京柯基数据科技有限公司成立于2015年,提供一站式全生命周期知识图谱构建和运维.智能应用服务,致力于"链接海量数据,从大数据中挖掘智慧".帮助企业运用知识 ...
- Codeforces Round #701 (Div. 2) 题解
由于今天实在是太自闭了就前来写场已经 AK 的 div.2 的题解了 这场比赛是我的 div.2 首 AK 哦 A 先特判 \(b=1\),强制将 \(b+1\) 否则容易发现答案最大为 \(\log ...
- CF Edu Round 71
CF Edu Round 71 A There Are Two Types Of Burgers 贪心随便模拟一下 #include<iostream> #include<algor ...
- 洛谷 P6667 - [清华集训2016] 如何优雅地求和(下降幂多项式,多项式)
题面传送门 wjz:<如何优雅地 AK NOI> 我:如何优雅地爆零 首先,按照这题总结出来的一个小套路,看到多项式与组合数结合的题,可以考虑将普通多项式转为下降幂多项式,因为下降幂和组合 ...
- centos 安装reids
1.安装tcl支持 yum install tcl 2.安装redis我们以最新的2.8.9为例 $ wget http://download.redis.io/releases/redis-2.8. ...
- Splay(伸展树)/HDU6873
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6873 题目大意 给定一组 \(n\) 列的方块,每列方块数 \(b_i\) ,现有 \(q\) 次操作 ...