zoukankan      html  css  js  c++  java
  • 2013 ACM/ICPC Asia Regional Chengdu Online hdu4731 Minimum palindrome

    Minimum palindrome

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

    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

    一看题目觉得挺难得,再看清楚的话,一道找规律的水题:

    当M=1时,很简单,输出N个a就行了;

    当M=2时,前8个没规律,后面的有规律的;

    当M=3时,”abc“这个字符串一直排到N个就行了;

    代码:

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string.h>
     4 #include <algorithm>
     5 #include <math.h>
     6 #include <stdlib.h>
     7 
     8 using namespace std;
     9 
    10 int main()
    11 {
    12     int t,i;
    13     cin>>t;
    14     int k=1;
    15     char a[200];
    16     while(t--)
    17     {
    18         int n,m;
    19         cin>>n>>m;
    20         cout<<"Case #"<<k++<<": ";
    21         if(n==1)
    22         {
    23             for(i=0; i<m; i++)
    24                 cout<<'a';
    25             cout<<endl;
    26         }
    27         else if(n>2)
    28         {
    29             for(i=0; i<m; i++)
    30                 cout<<(char)('a'+i%3);
    31             cout<<endl;
    32         }
    33         else
    34         {
    35             char b[8][30]= {"a",
    36                             "ab",
    37                             "aab",
    38                             "aabb",
    39                             "aaaba",
    40                             "aaabab",
    41                             "aaababb",
    42                             "aaababbb"
    43                            };
    44             if(m<=8)
    45             {
    46                 cout<<b[m-1]<<endl;
    47             }
    48             else
    49             {
    50                 cout<<"aa";
    51                 m--;
    52                 m--;
    53                 for(i=0;i<m/6;i++)
    54                 cout<<"aababb";
    55                 if(m%6==1)
    56                 cout<<'a';
    57                 else
    58                 if(m%6==2)
    59                 cout<<"aa";
    60                 else
    61                 if(m%6==3)
    62                 cout<<"aaa";
    63                 if(m%6==4)
    64                 cout<<"aaaa";
    65                 if(m%6==5)
    66                 cout<<"aabab";
    67                 cout<<endl;
    68             }
    69         }
    70     }
    71     }
    View Code
  • 相关阅读:
    人脸识别总结(附开源项目代码与各大数据集下载路径)
    simpledet 的配置
    论文笔记--PCN:Real-Time Rotation-Invariant Face Detection with Progressive Calibration Networks
    smallcorgi/Faster-RCNN_TF训练自己的数据
    保存文件名至txt文件中,不含后缀
    训练 smallcorgi/Faster-RCNN_TF 模型(附ImageNet model百度云下载地址)
    调试 smallcorgi/Faster-RCNN_TF 的demo过程遇到的问题
    python字符串前缀和格式化
    摩斯电码与字母相互转换
    django配置mysql
  • 原文地址:https://www.cnblogs.com/ERKE/p/3323238.html
Copyright © 2011-2022 走看看