uva 12012 - Detection of Extraterrestrial(KMP)



题目链接:uva 12012 - Detection of Extraterrestrial

题目大意:给定一个字符串,问说子串中,循环次数为k个最大长度为多少。

解题思路:枚举起点位置,然后用KMP处理。


#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int maxn = 1005;

int jump[maxn], c[maxn];

void get_jump (char* s, int n) {
    int p = 0;
    jump[0] = jump[1] = 0;
    for (int i = 2; i <= n; i++) {
        while (p && s[p+1] != s[i])
            p = jump[p];

        if (s[p+1] == s[i])
            p++;

        jump[i] = p;
    }
}

int main () {
    int cas;
    char s[maxn];
    scanf("%d", &cas);

    for (int kcas = 1; kcas <= cas; kcas++) {
        scanf("%s", s+1);

        int n = strlen(s+1);
        memset(c, 0, sizeof(c));

        for (int t = 0; t < n; t++) {
            int m = n - t;
            get_jump(s + t, m);

            for (int j = 1; j <= m; j++) {
                int p = j;
                while (p) {

                    p = jump[p];
                    if (j % (j - p) == 0) {
                        int k = j / (j - p);
                        c[k] = max(c[k], j);
                    }
                }
            }
        }

        printf("Case #%d:", kcas);
        for (int i = 1; i <= n; i++)
            printf(" %d", c[i]);
        printf("\n");
    }
    return 0;
}


题目链接:uva 12012 - Detection of Extraterrestrial

题目大意:给定一个字符串,问说子串中,循环次数为k个最大长度为多少。

解题思路:枚举起点位置,然后用KMP处理。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Mars is the fourth planet in our solar system and is known as the "Red Planet" due to its reddish appearance. It is roughly half the size of Earth and has a thin atmosphere composed mainly of carbon dioxide. Mars has long been of interest to humans due to its potential for supporting life and its proximity to Earth. Space exploration is important for several reasons. Firstly, it allows us to learn more about the universe and how it works, which can help us understand our place in it. Secondly, it allows us to search for extraterrestrial life and to study planets like Mars for potential colonization or resource extraction. Thirdly, space exploration has a significant impact on technological advancement and innovation, leading to spin-off technologies that can benefit society in a variety of ways. Mars exploration, in particular, has received a great deal of attention in recent years due to its potential for supporting human life. Scientists believe that Mars once had a more Earth-like environment and may have supported microbial life in the past. Studying Mars can help us better understand the conditions necessary for life to exist and how we might create those conditions on other planets in the future. In addition, Mars has the potential to serve as a location for human settlement or resource extraction. Mars contains a variety of minerals and resources that could be valuable in future space exploration or even back on Earth. Colonizing Mars would also provide backup for human civilization in the event of a catastrophic event on Earth. Overall, space exploration, and Mars exploration in particular, are crucial for advancing our understanding of the universe and our place in it, discovering potential extraterrestrial life, and laying the foundation for future human settlement and resource extraction.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值