【37.68%】【hdu 5918】Sequence I
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 706 Accepted Submission(s): 266
Problem Description
Mr. Frog has two sequences a1,a2,?,an and b1,b2,?,bm and a number p. He wants to know the number of positions q such that sequence b1,b2,?,bm is exactly the sequence aq,aq+p,aq+2p,?,aq+(m?1)p where q+(m?1)p≤n and q≥1.
Input
The first line contains only one integer T≤100, which indicates the number of test cases.
Each test case contains three lines.
The first line contains three space-separated integers 1≤n≤106,1≤m≤106 and 1≤p≤106.
The second line contains n integers a1,a2,?,an(1≤ai≤109).
the third line contains m integers b1,b2,?,bm(1≤bi≤109).
Output
For each test case, output one line “Case #x: y”, where x is the case number (starting from 1) and y is the number of valid q’s.
Sample Input
2
6 3 1
1 2 3 1 2 3
1 2 3
6 3 2
1 3 2 2 3 1
1 2 3
Sample Output
Case #1: 2
Case #2: 1
Source
2016中國大學生程序設計競賽(長春)-重現賽
【題解】
意思是讓你在
a1,a1+p,a1+2p,a1+3p…
a2,a2+p,a2+2p,a2 + 3p..
a3,a3+p,a3+2p,a3 +3p
…
ap,ap+p,ap+2p,ap+3p..
(a右邊的東西都是下標;)
這p個序列里面找b數組的匹配數目;
用vector類處理出這個p個數列就好。
剩下的用KMP算法解決。
找完一個匹配之后,j==m。
這個時候讓j= f[j];
就能繼續找匹配了。
記住就好。不然每次都想好煩。
轉載于:https://www.cnblogs.com/AWCXV/p/7632169.html
總結
以上是生活随笔為你收集整理的【37.68%】【hdu 5918】Sequence I的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 零基础逆向工程24_C++_01_类_t
- 下一篇: 女人梦到大老鼠是什么意思