Codeforces Round #374 (Div. 2) B. Passwords —— 基础题
题目链接:http://codeforces.com/contest/721/problem/B
2 seconds
256 megabytes
standard input
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).
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.
Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively.
5 2
cba
abc
bb1
abC
ABC
abc
1 15
4 100
11
22
1
2
22
3 4
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.
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 length 2 and only then the right one, spending 4 seconds
at all.
题解:
1.首先,用string肯定比char方便很多。其次,由于长度最大只为100, 所以可以开个 len[100]数组,记录每种长度下有多少个字符串,(特例:passwords只记录一次,因为一遇到passwords就结束了)。
2.不管最大值还是最小值,都需要将长度小于passwords的字符串走完,对于最小情况,走的第一个长度等于passwords的字符,即为passwords; 对于最大情况, 走的最后一个长度等于passwords的字符,即为passwords。
细节:当到达终点的那一刻,如果正好走了k*i步,他也不需要罚时,因为已经到达终点了,需要特判一下。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#include <algorithm>
using namespace std;
#define ms(a, b) memset((a), (b), sizeof(a))
typedef long long LL;
const double eps = 1e-6;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+7;
const int maxn = 100+10; int n, len[maxn], k;
string s[maxn], x; void init()
{
cin>>n>>k;
for(int i = 1; i<=n; i++)
cin>>s[i];
cin>>x;
} void solve()
{
int B = 0;
for(int i = 1; i<=n; i++)
{
if(s[i]==x)
{
if(!B)
len[x.size()]++, B = 1;
}
else
len[s[i].size()]++;
} int sum = 0;
for(int i = 1; i<x.size(); i++)
sum += len[i]; int t1 = sum + 1;
int minn = t1 + (t1/k)*5;
if(t1%k==0) minn -= 5; int t2 = sum + len[x.size()];
int maxx = t2 + (t2/k)*5;
if(t2%k==0) maxx -= 5; printf("%d %d\n",minn, maxx);
} int main()
{
// int T;
// scanf("%d",&T);
// while(T--)
{
init();
solve();
}
return 0;
}
Codeforces Round #374 (Div. 2) B. 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 #524 (Div. 2)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
- Codeforces Round #374 (Div. 2) A. One-dimensional Japanese Crossword —— 基础题
题目链接:http://codeforces.com/contest/721/problem/A A. One-dimensional Japanese Crossword time limit pe ...
- Codeforces Round #374 (Div. 2) C. Journey —— DP
题目链接:http://codeforces.com/contest/721/problem/C C. Journey time limit per test 3 seconds memory lim ...
- Codeforces Round #374 (Div. 2) A B C D 水 模拟 dp+dfs 优先队列
A. One-dimensional Japanese Crossword time limit per test 1 second memory limit per test 256 megabyt ...
- 拓扑序+dp Codeforces Round #374 (Div. 2) C
http://codeforces.com/contest/721/problem/C 题目大意:给你有向路,每条路都有一个权值t,你从1走到n,最多花费不能超过T,问在T时间内最多能访问多少城市? ...
- Codeforces Round #374 (Div. 2) D. Maxim and Array 贪心
D. Maxim and Array 题目连接: http://codeforces.com/contest/721/problem/D Description Recently Maxim has ...
- Codeforces Round #374 (Div. 2) C. Journey DP
C. Journey 题目连接: http://codeforces.com/contest/721/problem/C Description Recently Irina arrived to o ...
- Codeforces Round #374 (Div. 2) A. One-dimensional Japanese Crosswor 水题
A. One-dimensional Japanese Crossword 题目连接: http://codeforces.com/contest/721/problem/A Description ...
随机推荐
- (五)github删除仓库
一.一直学习怎么创建仓库,创建了太多仓库,一直不知道咋删除,有点懵,其实很简单,就是对英文不太习惯,要加深英文水平. 找到setting,然后再下面找到danger Zone
- Centos7源码安装MySQL5.7
a.连接数据库报111 从一台linux远程连接另一台linux上的MySQL,出现ERROR 2003 (HY000): Can't connect to MySQL server on 'xxx. ...
- Django-自己写的py文件调用models&Non-ASCII character报错&url接收参数
1.这个设置是网上能查到的最多的,但是没解决我的问题: Django的models.py在外部独立使用,新建一个文件夹,和monitor1目录平级 import sys,os sys.path.app ...
- spring mvc 编写处理带参数的Controller
在上一随笔记录的基础上,现记录编写处理带有参数的Controller. @Controller //这个注解会告知<context:component:scan> 将HomeControl ...
- jQuery使用on()绑定动态生成元素的事件无效
jquery on()方法是jquery1.7+后才使用的 由于需求:动态添加了以下代码 <tr class="pj" data-val="no"> ...
- iOS开发之Xcode8兼容适配iOS 10资料整理笔记
1.Notification(通知) 自从Notification被引入之后,苹果就不断的更新优化,但这些更新优化只是小打小闹,直至现在iOS 10开始真正的进行大改重构,这让开发者也体会到UserN ...
- gvim的常用编辑快捷键
gvim的快捷键很多,很难记全,但是入门初期应该找过几种基本的命令 下面结合自己常用到的介绍下 光标跳转: 0:行首 $:行尾 e:下一个单词的结尾 w:下一个单词的开头 b:上一个单词 H:当前页面 ...
- python matplotlib imshow热图坐标替换/映射
今天遇到了这样一个问题,使用matplotlib绘制热图数组中横纵坐标自然是图片的像素排列顺序, 但是这样带来的问题就是画出来的x,y轴中坐标点的数据任然是x,y在数组中的下标, 实际中我们可能期望坐 ...
- Git以及github的使用方法(三),git status查看工作区的状态,git diff查看具体修改内容
我们已经成功地添加并提交了一个readme.txt文件,现在,是时候继续工作了,于是,我们继续修改readme.txt文件,改成如下内容: Git is a distributed version c ...
- VUE高仿饿了么app开发思维导图
来自互联网 文章来源:刘俊涛的博客 地址:http://www.cnblogs.com/lovebing