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