题目链接:

B. Passwords

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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

Input

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.

Output

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.

Examples
input
5 2
cba
abc
bb1
abC
ABC
abc
output
1 15
input
4 100
11
22
1
2
22
output
3 4

题意:
给了一堆密码,然后按长度从小到大开始试,问最少和最多的花费时间; 思路: 贪心; AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
#define lson o<<1
#define rson o<<1|1
typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const LL inf=1e18;
const int N=1e6+10;
const int maxn=1e5+10;
const double eps=1e-12; int n,k,a[200];
string s[200],ans;
int main()
{
read(n);read(k);
for(int i=1;i<=n;i++){cin>>s[i],a[i]=s[i].length();}
cin>>ans;
int len=ans.length(),mi=0,eq=0;
for(int i=1;i<=n;i++)
{
if(a[i]<len)mi++;
else if(a[i]==len)eq++;
}
cout<<mi+mi/k*5+1<<" "<<mi+eq+(mi+eq-1)/k*5<<endl; return 0;
}

  

codeforces 721B B. Passwords(贪心)的更多相关文章

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

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

  2. codeforces 704B - Ant Man 贪心

    codeforces 704B - Ant Man 贪心 题意:n个点,每个点有5个值,每次从一个点跳到另一个点,向左跳:abs(b.x-a.x)+a.ll+b.rr 向右跳:abs(b.x-a.x) ...

  3. CodeForces - 50A Domino piling (贪心+递归)

    CodeForces - 50A Domino piling (贪心+递归) 题意分析 奇数*偶数=偶数,如果两个都为奇数,最小的奇数-1递归求解,知道两个数都为1,返回0. 代码 #include ...

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

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

  5. CodeForces 721B Passwords (水题)

    题意:给定 n 个密码,你要按长度不递减的顺序进行尝试,问你最多和最少试多少次可能找出密码,每尝试 k 次错误的,就要等5秒. 析:我们只要把长度全都统计下来,然后从1开始去找目标长度,最少的就是正好 ...

  6. Codeforces 161 B. Discounts (贪心)

    题目链接:http://codeforces.com/contest/161/problem/B 题意: 有n个商品和k辆购物车,给出每个商品的价钱c和类别t(1表示凳子,2表示铅笔),如果一辆购物车 ...

  7. CodeForces 176A Trading Business 贪心

    Trading Business 题目连接: http://codeforces.com/problemset/problem/176/A Description To get money for a ...

  8. Codeforces Gym 100803C Shopping 贪心

    Shopping 题目连接: http://codeforces.com/gym/100803/attachments Description Your friend will enjoy shopp ...

  9. Codeforces 486C Palindrome Transformation(贪心)

    题目链接:Codeforces 486C Palindrome Transformation 题目大意:给定一个字符串,长度N.指针位置P,问说最少花多少步将字符串变成回文串. 解题思路:事实上仅仅要 ...

随机推荐

  1. C语言范例学习03-下

    树与图 3.5 二叉树及其应用 PS:二叉树是最经典的树形结构,适合计算机处理,具有存储方便和操作灵活等特点,而且任何树都可以转换成二叉树. 实例101 二叉树的递归创建 实例102 二叉树的遍历 问 ...

  2. Jaxb解析xml准换为javabean

    先说下这个的背景吧,前些日子,有个以前的小同事说刚接触webservice,想解析下xml,记得我学的时候还是dom4j,sax的解析方式,最近看别人的代码用的jaxb的方式,觉得注解起来很简练,所以 ...

  3. js得到屏幕宽高、页面宽高 (window.screen.availHeight)等--笔记

    window.screen.availWidth 返回当前屏幕宽度(空白空间) window.screen.availHeight 返回当前屏幕高度(空白空间) window.screen.width ...

  4. jquery操作radio单选按钮、checked复选框。

    一.radio 取值: $('input[name=radio]:checked').val(); 二.checked 判断checked是否被选中 $("input[type='check ...

  5. 硬盘变成RAW的修复过程

    可能在不知道为什么的情况下,移动硬盘或者本地磁盘的每个分区变成了RAW格式.其在Win系统下的无损修复过程如下: 用“win”+“R”打开“运行”小窗口: 键入“CMD”: 键入命令“CHKDSK P ...

  6. hadoop实战–搭建eclipse开发环境及编写Hello World

    原创文章,转载请注明: 转载自工学1号馆 欢迎关注我的个人博客:www.wuyudong.com, 更多云计算与大数据的精彩文章 1.在eclise中安装hadoop的插件并配置 在上篇文章<编 ...

  7. 全球最低功耗蓝牙单芯片DA14580的软件体系 -层次架构和BLE消息事件处理过程

    在作者之前发表的<全球最低功耗蓝牙单芯片DA14580的系统架构和应用开发框架分析>.<全球最低功耗蓝牙单芯片DA14580的硬件架构和低功耗>.<全球最低功耗蓝牙单芯片 ...

  8. Android UI之下拉刷新上拉刷新实现

    在实际开发中我们经常要用到上拉刷新和下拉刷新,因此今天我写了一个上拉和下拉刷新的demo,有一个自定义的下拉刷新控件 只需要在布局文件中直接引用就可以使用,非常方便,非常使用,以下是源代码: 自定义的 ...

  9. Git哲学与使用

    -- 故国神游,多情应笑我,早生华发. Git是什么? Git是一个版本控制工具,代码管理工具,团队协作工具.它跟SVN等传统工具实现同样的目的:但从某种程度来说,它更快,更灵活.我想绝大多数读者都已 ...

  10. rabbitmq-server启动不了,安装erlang,安装rabbitmq-server

    sudo rabbitmq-server start,虽然现实success,但是查看状态,sudo rabbitmq-server status发现居然没有启动,报错是不是端口占用(查看日志/var ...