当前位置: 代码迷 >> 综合 >> codeforces 721B B. Passwords -- by lethalboyd
  详细解决方案

codeforces 721B B. Passwords -- by lethalboyd

热度:20   发布时间:2023-09-30 17:51:10.0
题意:给了n个密码串,然后按长度从小到大开始试,同长度串任意顺序试,尝试k次后需等待5s再试,试一次1s,问最少和最多的花费时间;
记录待尝试的串中长度小于正确串的个数s,长度等于正确串的个数t
则:
    最少时间:s+s/k*5+1
    最大时间:t+s+(s+t-1)/k*5
附代码:
[cpp] view plaincopy
  1. #include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<cstdlib>
    #include<cmath>
    #include<cstring>
    #include<climits>
    #include<string>
    using namespace std;
    string s[222];
    int a[222];
    int n,k,m,num1,num2;
    bool operator < (string a,string b)
    {return a.size()<b.size();}
    int main()
    {
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){cin>>s[i];a[i]=s[i].size();}
    cin>>s[0];
    int m=s[0].size();
    for(int i=1;i<=n;i++)
    {
    if(a[i]<m)num1++;
    else if(a[i]==m)num2++;
    }
    printf("%d %d\n",num1+num1/k*5+1,num2+num1+(num2+num1-1)/k*5);
    }