奶牛哞叫&&无线传输

  1. [USACO09OCT]Barn Echoes G

## 题目描述

The cows enjoy mooing at the barn because their moos echo back, although sometimes not completely. Bessie, ever the excellent

secretary, has been recording the exact wording of the moo as it goes out and returns. She is curious as to just how much overlap there is.

Given two lines of input (letters from the set a..z, total length in the range 1..80), each of which has the wording of a moo on it, determine the greatest number of characters of overlap between one string and the other. A string is an overlap between two other strings if it is a prefix of one string and a suffix of the other string.

By way of example, consider two moos:

moyooyoxyzooo

yzoooqyasdfljkamo

The last part of the first string overlaps 'yzooo' with the first part of the second string. The last part of the second string

overlaps 'mo' with the first part of the first string. The largest overlap is 'yzooo' whose length is 5.

POINTS: 50

奶牛们非常享受在牛栏中哞叫,因为她们可以听到她们哞声的回音。虽然有时候并不能完全听到完整的回音。Bessie曾经是一个出色的秘书,所以她精确地纪录了所有的哞叫声及其回声。她很好奇到底两个声音的重复部份有多长。

输入两个字符串(长度为1到80个字母),表示两个哞叫声。你要确定最长的重复部份的长度。两个字符串的重复部份指的是同时是一个字符串的前缀和另一个字符串的后缀的字符串。

我们通过一个例子来理解题目。考虑下面的两个哞声:

moyooyoxyzooo

yzoooqyasdfljkamo

第一个串的最后的部份"yzooo"跟第二个串的第一部份重复。第二个串的最后的部份"mo"跟第一个串的第一部份重复。所以"yzooo"跟"mo"都是这2个串的重复部份。其中,"yzooo"比较长,所以最长的重复部份的长度就是5。

## 输入格式

\* Lines 1..2: Each line has the text of a moo or its echo

## 输出格式

\* Line 1: A single line with a single integer that is the length of the longest overlap between the front of one string and end of the other.

## 样例 #1

### 样例输入 #1

```

abcxxxxabcxabcd

abcdxabcxxxxabcx

```

### 样例输出 #1

```

11

```

## 提示

'abcxxxxabcx' is a prefix of the first string and a suffix of the second string.

思路:题目说重复部份指的是同时是一个字符串的前缀和另一个字符串的后缀的字符串,必须有前缀、后缀,不是普通意义上的重合。分两种情况:一是第一个字符串的前缀和第二个字符串的后缀相等,二是第一个字符串的后缀和第二个字符串的后缀相等。还有一个重点是求某区间的哈希值(有公式)。

  1. [BOI2009]Radio Transmission 无线传输

## 题目描述

给你一个字符串 $s_1$,它是由某个字符串 $s_2$ 不断自我连接形成的。但是字符串 $s_2$ 是不确定的,现在只想知道它的最短长度是多少。

## 输入格式

第一行一个整数 $L$,表示给出字符串的长度。

第二行给出字符串 $s_1$ 的一个子串,全由小写字母组成。

## 输出格式

仅一行,表示 $s_2$ 的最短长度。

## 样例 #1

### 样例输入 #1

```

8

cabcabca

```

### 样例输出 #1

```

3

```

## 提示

#### 样例输入输出 1 解释

对于样例,我们可以利用 $\texttt{abc}$ 不断自我连接得到 $\texttt{abcabcabc}$,读入的 $\texttt{cabcabca}$,是它的子串。

#### 规模与约定

对于全部的测试点,保证 $1 < L \le 10^6$。

思路:这题是由子串s2连接构成,s2的内部顺序没有打乱,求最小子串,相当于求最大公共串。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值