coderforces 721b
题目描述:
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.
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 5 seconds 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 length 2and only then the right one, spending 4 seconds at all.
题目大意:一些列字符串,输入一次时间加一秒,当错误次数达到k时,必须等待5秒才能继续输入下一次;求输入正确密码最短时间和最长时间。
总结:本题卡了一阵主要是一下3个方面:
1.题目描述的是: some of his n passwords.也就是说正确的密码可能会出现好几次(没仔细看题目惹的祸,上次也有这种情况,应多注意),而我认为只出现一次
2.if 之后的下一个判断没有加else,直接用的if -if导致第一个if可能改变了变量,使得满足第二个if的条件。应该if-else if(考虑不全面)
3.当出现正确密码时lcnt- 1;但是这样可能会导致负数,所以以后涉及减法时就应该考虑是否可能为负数(后来把lcnt设置成总数就不用考虑了)
#include<stdio.h>
#include<stdlib.h>
#define _max 105
char str[_max][_max];
int main()
{
int len[_max];
char r_pass[_max];
int i = 0, n = 0, k = 0;
int r_len = 0,scnt = 0,lcnt = 0,tt = 0;
scanf("%d%d",&n,&k);
for( i = 0; i < n; i++)
{
scanf("%s",str[i]);
len[i] = strlen(str[i]);
}
scanf("%s",r_pass);
r_len = strlen(r_pass); for( i = 0; i < n; i++)
{
if(len[i] < r_len)
scnt++;
if(len[i] == r_len)
{
lcnt++;
if(strcmp(str[i],r_pass) == 0)
tt++;
} }
lcnt+=scnt;//lcnt变成了总数
lcnt-=(tt -1);//减去重复的正确密码次数
if(scnt < k)
scnt =scnt + 1;
else if(scnt == k)
scnt = scnt + 6;
else if(scnt > k)
{
scnt = scnt + (scnt / k)*5 + 1;
}
if(lcnt <= k)
lcnt = lcnt; else if(lcnt > k)
{
if(lcnt %k == 0)
lcnt = lcnt + (lcnt/k - 1)*5;//当第n*k次时正好是正确密码,此时不用再等5秒了
else
lcnt = lcnt + (lcnt/k)*5;
}
printf("%d %d\n",scnt,lcnt); }
coderforces 721b的更多相关文章
- coderforces #387 Servers(模拟)
		
Servers time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
 - coderforces #384 D Chloe and pleasant prizes(DP)
		
Chloe and pleasant prizes time limit per test 2 seconds memory limit per test 256 megabytes input st ...
 - coderforces 731c
		
题目大意:给出m组数据,每组数据包括两个数Li与Ri,分别表示左右袜子的索引(下标),表示这一天要穿的袜子:而我们要使得每天穿的这两只袜子的颜色相同,所以可以改变袜子的颜色,每次只能改变一只袜子的颜色 ...
 - codeforces 721B B. Passwords(贪心)
		
题目链接: B. Passwords time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
 - CoderForces 280B(记忆化搜索)
		
题目大意:一个纸牌游戏,52张纸牌排成一列,每张纸牌有面值和花色两种属性.每次操作可以用最后一张纸牌将倒数第二张或者倒数第四张替换,但前提是两张牌的花色或者面值相同.问最终能否只剩一张牌. 题目分析: ...
 - CodeForces 721B
		
B. Passwords time limit per test:2 seconds memory limit per test:256 megabytes input:standard input ...
 - CoderForces 689A Mike and Cellphone (水题)
		
题意:给定一个手机键盘数字九宫格,然后让你判断某种操作是不是唯一的,也就是说是不是可以通过平移也能实现. 析:我的想法是那就平移一下,看看能实现,就四种平移,上,下,左,右,上是-3,要注意0变成8, ...
 - CoderForces 518C Anya and Smartphone (模拟)
		
题意:给定一个手机,然后一共有 n 个app,告诉你每个屏幕最多放 k 个,现在要你运行 m 个app,每次都从第一个屏幕开始滑动,每运行一个,它就和前一个交换位置,第一个就不换了,现在问你要滑动多少 ...
 - CoderForces 518D Ilya and Escalator (期望DP)
		
题意:给定 n 个人,在每一时刻一个人进入地铁的概率是 p,站着不动的概率是 1-p,然后问你 t 时间地铁里有多少人. 析:很明显这是一个期望DP,用d[i][j]表示 i 时刻 j 个人进入地铁的 ...
 
随机推荐
- 【LeetCode OJ】Symmetric Tree
			
Problem Link: https://oj.leetcode.com/problems/symmetric-tree/ To solve the problem, we can traverse ...
 - HDU5840 (分块+树链剖分)
			
Problem This world need more Zhu 题目大意 给一颗n个点的有点权的树,有m个询问,对于每个询问u,v,k,首先将点u到点v的最短路径上的所有点按顺序编号,u的编号为1, ...
 - IOS 关于开发的APP跳转第三方应用的心得
			
昨天晚上自己做了个APP,想做个功能可以去跳转到手机上的微博,微信.找了好些资料,下面总结下自己的心得. 跳转的核心代码如下: if ([[UIApplication sharedApplicatio ...
 - MTP in Android详解
			
MTP in Android详解 最近好长一段时间没有做笔记了,今天主要学习一下MTP相关的知识. MTP的全称是Media Transfer Protocol(媒体传输协议),它是微软公司提出的一套 ...
 - 学习笔记-- android动画简述
			
android支持三种类型的动画: ·属性动画 一种补间动画,通过在目标对象的任何属性的两个值之间应用赠了变化,可以生成一种动画效果.这种动画可以用来生成各种效果,例如:改变视图的颜色.透明条.淡入 ...
 - c#小小总结(设计模式)
			
前言 对于设计模式,知道一些(当然有些仅限于知道而已) 内容 1.单例模式 2.建造者模式 把单个模块通过不同的搭配方式创造出不同的产品 3.观察者模式 一对多的行为 当“一”改变的时候 “多”的每 ...
 - 《剑指offer》面试题12:打印1到最大的n位数
			
面试题12:打印1到最大的n位数 剑指offer题目12,题目如下 输入数字n,按顺序打印出1到最大的n位十进制数,比如输入3,则打印出1,2,3一直到最大的三位数999 方法一 和面试题11< ...
 - gulp基本用法
			
嗨,小伙伴们,大家周五好,又到了一周中最最最期待的周五啦啦~~~ 这几天一直在研究gulp的使用方法,今天抽时间来整理一下基本步骤. gulp 的使用流程: 安装nodejs ->安装git(方 ...
 - 编译.NET项目的时候报错错误“ResGen.exe”已退出,代码为 -1073741701
			
解决的办法如下: 1.关闭所有Visual Studio: 2.以管理员的身份打开命令提示窗口:(开始-运行-cmd) //有人说要使用vs tools 里面的控制台 亲试无卵用 3. ...
 - C# 模拟按下回车键自动登录
			
private void Form1_Load(object sender, EventArgs e) { //this.Show(); this.Activate(); //this.Focus() ...