• Codeforces Round #394 (Div. 2) C. Dasha and Password


    C. Dasha and Password
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length n which satisfies the following requirements:

    • There is at least one digit in the string,
    • There is at least one lowercase (small) letter of the Latin alphabet in the string,
    • There is at least one of three listed symbols in the string: '#', '*', '&'.

    Considering that these are programming classes it is not easy to write the password.

    For each character of the password we have a fixed string of length m, on each of these n strings there is a pointer on some character. The i-th character displayed on the screen is the pointed character in the i-th string. Initially, all pointers are on characters with indexes 1 in the corresponding strings (all positions are numbered starting from one).

    During one operation Dasha can move a pointer in one string one character to the left or to the right. Strings are cyclic, it means that when we move the pointer which is on the character with index 1 to the left, it moves to the character with the index m, and when we move it to the right from the position m it moves to the position 1.

    You need to determine the minimum number of operations necessary to make the string displayed on the screen a valid password.

    Input

    The first line contains two integers nm (3 ≤ n ≤ 50, 1 ≤ m ≤ 50) — the length of the password and the length of strings which are assigned to password symbols.

    Each of the next n lines contains the string which is assigned to the i-th symbol of the password string. Its length is m, it consists of digits, lowercase English letters, and characters '#', '*' or '&'.

    You have such input data that you can always get a valid password.

    Output

    Print one integer — the minimum number of operations which is necessary to make the string, which is displayed on the screen, a valid password.

    Examples
    input
    3 4
    1**2
    a3*0
    c4**
    output
    1
    input
    5 5
    #*&#*
    *a1c&
    &q2w*
    #a3c#
    *&#*&
    output
    3
    Note

    In the first test it is necessary to move the pointer of the third string to one left to get the optimal answer.

    In the second test one of possible algorithms will be:

    • to move the pointer of the second symbol once to the right.
    • to move the pointer of the third symbol twice to the right

    题意:

    给你一个n*m的字符串,移动字符下面的指标,是的指到的字符包括三部分数字,字母,'#'或'*'或'&',注意每一行是环形。所以要考虑倒着移

    可以先将这三部分转换为数字方便计算。

    int fuck(char c){
        if('0'<=c&&c<='9')
            return 0;
        if('a'<=c&&c<='z')
            return 1;
        else
            return 2;
    }

    然后用dp分别推出每一行获得0,1,2三种状态的最少操作

    最后用三重循环遍历一下找出最少总操作数。

    代码很简单就不贴了

  • 相关阅读:
    【Oracle】子查询、伪列、分页查询、表连接
    【Oracle】dual、sysdate、systimestamp、单行(组)函数、sql执行顺序
    【Oracle】简介、简单查询、去重、排序
    【Java】注解的使用
    【Java】反射机制
    【Java】网络编程(NIO/BIO)
    【Java】枚举
    【Java】File操作
    【Java】多线程
    Hibernate 再接触 关系映射 一对一单向外键关联
  • 原文地址:https://www.cnblogs.com/kls123/p/7115670.html
Copyright © 2020-2023  润新知