• 2013 ACM/ICPC Asia Regional Chengdu Online 1004 Minimum palindrome


    Minimum palindrome

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 586    Accepted Submission(s): 110


    Problem Description
    Setting password is very important, especially when you have so many "interesting" things in "F:TDDOWNLOAD".
    We define the safety of a password by a value. First, we find all the substrings of the password. Then we calculate the maximum length of those substrings which, at the meantime, is a palindrome.
    A palindrome is a string that will be the same when writing backwards. For example, aba, abba,abcba are all palindromes, but abcab, abab are not.
    A substring of S is a continous string cut from S. bcd, cd are the substrings of abcde, but acd,ce are not. Note that abcde is also the substring of abcde.
    The smaller the value is, the safer the password will be.
    You want to set your password using the first M letters from the alphabet, and its length should be N. Output a password with the smallest value. If there are multiple solutions, output the lexicographically smallest one.
    All the letters are lowercase.
     
    Input
    The first line has a number T (T <= 15) , indicating the number of test cases.
    For each test case, there is a single line with two integers M and N, as described above.(1 <= M <= 26, 1 <= N <= 105)
     
    Output
    For test case X, output "Case #X: " first, then output the best password.
     
    Sample Input
    2
    2 2
    2 3
     
    Sample Output
    Case #1: ab
    Case #2: aab
     
    3个及3个以上字母就可以不构成回文串,2个字母的打表找规律
     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 
     5 using namespace std;
     6 
     7 int main()
     8 {
     9     int T;
    10     int cas=1;
    11     scanf("%d",&T);
    12     while(T--)
    13     {
    14         int n,m;
    15         scanf("%d%d",&n,&m);
    16         printf("Case #%d: ",cas++);
    17         if(n==1)
    18         {
    19             while(m--)
    20                 putchar('a');
    21             putchar(10);
    22             continue;
    23         }
    24         if(n==2)
    25         {
    26             if(m<=8)
    27             {
    28                 switch(m)
    29                 {
    30                 case 1:
    31                     printf("a
    "); break;
    32                 case 2:
    33                     printf("ab
    "); break;
    34                 case 3:
    35                     printf("aab
    "); break;
    36                 case 4:
    37                     printf("aabb
    "); break;
    38                 case 5:
    39                     printf("aaaba
    "); break;
    40                 case 6:
    41                     printf("aaabab
    "); break;
    42                 case 7:
    43                     printf("aaababb
    "); break;
    44                 case 8:
    45                     printf("aaababbb
    "); break;
    46                 }
    47                 continue ;
    48             }
    49             else
    50             {
    51                 printf("aaaababb");
    52                 m-=8;
    53                 int l=m/6;
    54                 for(int i=0;i<l;i++)
    55                 {
    56                     printf("aababb");
    57                 }
    58                 l=m%6;
    59                 switch(l)
    60                 {
    61                 case 1:
    62                     printf("a
    "); break;
    63                 case 2:
    64                     printf("aa
    "); break;
    65                 case 3:
    66                     printf("aaa
    "); break;
    67                 case 4:
    68                     printf("aaaa
    "); break;
    69                 case 5:
    70                     printf("aabab
    "); break;
    71                 }
    72             }
    73         }
    74         else
    75         {
    76             for(int i=0;i<m;i++)
    77             {
    78                 putchar('a'+(i)%3);
    79             }
    80             putchar(10);
    81         }
    82     }
    83 
    84     return 0;
    85 }
     
  • 相关阅读:
    [SUCTF 2019]Pythonginx
    [极客大挑战 2019]BuyFlag
    [GXYCTF2019]Ping Ping Ping
    git 常用命令记录
    webpack4.X + react-router 路由跳转
    webpack4.X + react搭建
    windows 下 node 安装 react
    valueOf()、toString()
    isFinite()
    Javascript 闭包
  • 原文地址:https://www.cnblogs.com/CKboss/p/3321573.html
Copyright © 2020-2023  润新知