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 题解的更多相关文章

  1. Codeforces Round #374 (Div. 2) B. Passwords 贪心

    B. Passwords 题目连接: http://codeforces.com/contest/721/problem/B Description Vanya is managed to enter ...

  2. Codeforces Round #374 (Div. 2) B. Passwords —— 基础题

    题目链接:http://codeforces.com/contest/721/problem/B B. Passwords time limit per test 2 seconds memory l ...

  3. 【37.21%】【codeforces 721B】Passwords

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 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, ...

  5. 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 ...

  6. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  7. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  8. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  9. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

随机推荐

  1. 痞子衡嵌入式:深扒IAR启动函数流程之段初始化函数__iar_data_init3实现

    大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家分享的是IAR启动函数流程里的段初始化函数__iar_data_init3实现. 本篇是 <IAR启动函数流程及其__low_level_ ...

  2. 解决mac电脑耳机/外放突然无声音

    问题现象 mac电脑基本不会关机,近期发送隔一段时间出现网易云音乐可以播放但是耳机.外放均无声音的问题.此时,电脑本身的声音提示.远程会议声音均正常. 解决方法 网上搜了一圈解决方案,最后发现是输出设 ...

  3. Perl去重fasta序列

    常规方法 #! usr/bin/perl -w use strict; my $input=shift; my %hash; open IN,"<$input"; $/=&q ...

  4. 基于PASA进行基因预测

    PASA, acronym for Program to Assemble Spliced Alignments, is a eukaryotic genome annotation tool tha ...

  5. Docker-Mysql-proxy Mysql Proxy实现读写分离

      Docker-Mysql-proxy Mysql实现读写分离与负载 原理 MySQL Proxy处于客户端应用程序和MySQL服务器之间,通过截断.改变并转发客户端和后端数据库之间的通信来实现其功 ...

  6. Java日期时间操作基础——包含JDK1.8时间操作新特性

    JDK1.7日期时间操作 示例小结 public class DateTest { public static final String FORMAT_DATE = "yyyy-MM-dd& ...

  7. 【模板】单源最短路径(Dijkstra)/洛谷P4779

    题目链接 https://www.luogu.com.cn/problem/P4779 题目大意 给定一个 \(n\) 个点 \(m\) 条边有向图,每个点有一个非负权值,求从 \(s\) 点出发,到 ...

  8. 阿里云ECS磁盘性能测试

    阿里官方给出的性能指标 顺序读 测试命令 fio -directory=/var/lib/data -direct=1 -iodepth=1 -thread -ioengine=libaio -ran ...

  9. Hadoop运行jar包报错java.lang.Exception: java.lang.ArrayIndexOutOfBoundsException: 1

    错误信息: java.lang.Exception: java.lang.ArrayIndexOutOfBoundsException: 1    at org.apache.hadoop.mapre ...

  10. add more

    # -*- coding: utf-8 -*- print('123', 123) print(type('123'), type(123)) # string, integer /ˈintidʒə/ ...