Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice.
Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password k times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that.
Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds).
The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.
The next n lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters.
The last line of the input contains the Vanya's Codehorses password. It is guaranteed that the Vanya's Codehorses password is equal to some of his n passwords.
Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he enters another 4 passwords before. He spends 2 seconds to enter first 2 passwords, then he waits 5seconds as soon as he made 2 wrong tries. Then he spends 2 more seconds to enter 2 wrong passwords, again waits 5 seconds and, finally, enters the correct password spending 1 more second. In summary in the worst case he is able to be authorized in 15 seconds.
5 2 cba abc bb1 abC ABC abc
1 15
4 100 11 22 1 2 22
3 4
Consider the second sample case. There is no way of entering passwords and get the access to the site blocked. As soon as the required password has length of 2, Vanya enters all passwords of length 1 anyway, spending 2 seconds for that. Then, in the best case, he immediately enters the correct password and the answer for the best case is 3, but in the worst case he enters wrong password of length2 and only then the right one, spending 4 seconds at all.
不要被 he,不要被hei........
题意:
键入 n 行密码,最后给定正确的密码。每次键入错 k 次后需要等待 5 秒后才能继续键入,
问键入密码成功的最短和最长时间。
不明白是不是密码的键入是默认字符串有长到短。
思路:
记录每个长度字符串的个数,记住的就是:长度有短到长键入,最少次数和最多次数见代码
CODE:
/*
_,add8ba,
,d888888888b,
d8888888888888b _,ad8ba,_
d888888888888888) ,d888888888b,
I8888888888888888 _________ ,8888888888888b
__________`Y88888888888888P"""""""""""baaa,__ ,888888888888888,
,adP"""""""""""9888888888P""^ ^""Y8888888888888888I
,a8"^ ,d888P"888P^ ^"Y8888888888P'
,a8^ ,d8888' ^Y8888888P'
a88' ,d8888P' I88P"^
,d88' d88888P' "b,
,d88' d888888' `b,
,d88' d888888I `b,
d88I ,8888888' ___ `b,
,888' d8888888 ,d88888b, ____ `b,
d888 ,8888888I d88888888b, ,d8888b, `b
,8888 I8888888I d8888888888I ,88888888b 8,
I8888 88888888b d88888888888' 8888888888b 8I
d8886 888888888 Y888888888P' Y8888888888, ,8b
88888b I88888888b `Y8888888^ `Y888888888I d88,
Y88888b `888888888b, `""""^ `Y8888888P' d888I
`888888b 88888888888b, `Y8888P^ d88888
Y888888b ,8888888888888ba,_ _______ `""^ ,d888888
I8888888b, ,888888888888888888ba,_ d88888888b ,ad8888888I
`888888888b, I8888888888888888888888b, ^"Y888P"^ ____.,ad88888888888I
88888888888b,`888888888888888888888888b, "" ad888888888888888888888'
8888888888888698888888888888888888888888b_,ad88ba,_,d88888888888888888888888
88888888888888888888888888888888888888888b,`"""^ d8888888888888888888888888I
8888888888888888888888888888888888888888888baaad888888888888888888888888888'
Y8888888888888888888888888888888888888888888888888888888888888888888888888P
I888888888888888888888888888888888888888888888P^ ^Y8888888888888888888888'
`Y88888888888888888P88888888888888888888888888' ^88888888888888888888I
`Y8888888888888888 `8888888888888888888888888 8888888888888888888P'
`Y888888888888888 `888888888888888888888888, ,888888888888888888P'
`Y88888888888888b `88888888888888888888888I I888888888888888888'
"Y8888888888888b `8888888888888888888888I I88888888888888888'
"Y88888888888P `888888888888888888888b d8888888888888888'
^""""""""^ `Y88888888888888888888, 888888888888888P'
"8888888888888888888b, Y888888888888P^
`Y888888888888888888b `Y8888888P"^
"Y8888888888888888P `""""^
`"YY88888888888P'
^""""""""'
*/
#include<stdio.h>
#include<cstring>
#include<algorithm>
#define AC main()
using namespace std;
const int MYDD = 1103;
int AC {
int n, k, len[MYDD], lenans;
char a[113];
scanf("%d %d", &n, &k);
for(int j = 0; j < MYDD; j++) len[j] = 0;
for(int j = 0; j < n + 1; j++) {
scanf("%s", a);
if(j == n) {
lenans = strlen(a);//答案字符串的长度
break;
}
len[strlen(a)]++;
}
int cnt = 0;
for(int j = 0; j < lenans; j++) {
cnt += len[j];
}
int Min = cnt + cnt/k * 5 + 1;
cnt = -1;
for(int j = 0; j <= lenans; j++) {
cnt += len[j];
}
int Max = cnt + cnt/k * 5 + 1;
printf("%d %d\n", Min, Max);
return 0;
}
/*
5 4
12
23
43
546
123
123
4 10
*/
密码输入策略分析

本文探讨了一个关于密码输入的问题,分析了在限定条件下输入密码所需的最短及最长时间。通过记录不同长度密码的数量,并考虑错误输入后的等待时间,文章提供了解决这一问题的有效算法。
1278

被折叠的 条评论
为什么被折叠?



