zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    6、函数、谓词、CASE表达式
    25. k个一组翻转链表
    78. 子集
    72. 编辑距离
    12. 整数转罗马数字
    287. 寻找重复数
    27. 移除元素
    91. 解码方法
    283. 移动零
    198. 打家劫舍
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11385418.html
Copyright © 2011-2022 走看看