zoukankan      html  css  js  c++  java
  • HDU 4731 Minimum palindrome 2013 ACM/ICPC 成都网络赛

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4731

    题解:规律题,我们可以发现当m大于等于3时,abcabcabc……这个串的回文为1,并且字典数最小,

    m等以1时,直接输出n个a,

    现在要解决的就是m=2的情况:

    通过自己再纸上面写可以得出当n大于等于9时,最大的回文为4,要字典数最小,所以前四个都为a,后面也可以找到一个最小循环结:babbaa

    但是还要讨论最后还剩余几个,如果是小于等于两个,那么添加2个a,否则按循环结添加。

    AC代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <vector>
    #include <list>
    #include <deque>
    #include <queue>
    #include <iterator>
    #include <stack>
    #include <map>
    #include <set>
    #include <algorithm>
    #include <cctype>
    using namespace std;
    
    typedef __int64 xiaohao;
    typedef long long LL;
    const int N=100090;
    const int INF=0x3f3f3f3f;
    const double PI=acos(-1.0);
    const double eps=1e-7;
    
    const char tab[8][20] =
    { "a", "ab", "aab", "aabb", "aaaba", "aaabab", "aaababb", "aaababbb"};
    
    int main()
    {
        int T,se=0;
        scanf("%d",&T);
        while(T--)
        {
            int m, n;
            scanf("%d%d",&m,&n);
            printf("Case #%d: ", ++se);
            if(m>2)
            {
                int a = n / 3;
                int b = n % 3;
                for(int i=0;i<a;i++)
                    printf("abc");
                for(int i=0;i<b;i++)
                    printf("%c",'a'+i);
                printf("
    ");
            }
            else if(m == 1)
            {
                for(int i=0;i<n;i++)
                    putchar('a');
                printf("
    ");
            }
            else
            {
                if(n < 9)
                {
                    printf("%s
    ", tab[n-1]);
                }
                else
                {
                    char t[] = "babbaa";
                    printf("aaaa");
                    int a = (n-4) / 6;
                    int b = (n-4) % 6;
                    for(int i=0;i<a;i++) printf("babbaa");
                    if(b <= 2) for(int i=0;i<b;i++) putchar('a');
                    else for(int i=0;i<b;i++) putchar(t[i]);
                    printf("
    ");
                }
            }
        }
        return 0;
    }
    


     

  • 相关阅读:
    local 不能解析为127.0.0.1
    完全使用接口方式调用WCF 服务
    【人生】自己对于求职应聘的一些感受
    OO的经典例子
    剪刀、石头、布机器人比赛
    TextTree 文本资料收集轻量级工具
    两个代替重复输入的小工具
    桌面助手 Desktop Helper 自动帮你关闭指定的窗口
    磁盘可用空间平衡
    用C#制造可以继承的“枚举”
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3323032.html
Copyright © 2011-2022 走看看