CodeForces-721B-Passwords

链接:

https://vjudge.net/problem/CodeForces-721B

题意:

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

思路:

算一下长度小的字符串要花的时间和长度相等要花的时间即可.

代码:

#include <bits/stdc++.h>
using namespace std;

string s[110];

bool cmp(string a, string b)
{
    return a.length() < b.length();
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    string ss;
    cin >> n >> k;
    for (int i = 1;i <= n;i++)
        cin >> s[i];
    cin >> ss;
    sort(s+1, s+1+n, cmp);
    int small = 0, same = 0;
    for (int i = 1;i <= n;i++)
    {
        if (s[i].length() > ss.length())
            break;
        if (s[i].length() < ss.length())
            small++;
        if (s[i].length() == ss.length())
            same++;
    }
    int mmin = small+1+(small/k)*5;
    int mmax = small+same+((small+same-1)/k)*5;
    cout << mmin << ' ' << mmax << endl;

    return 0;
}

转载于:https://www.cnblogs.com/YDDDD/p/11385418.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值