SDNU 1260.Problem H. The chord 最长公共子串

1260.Problem H. The chord
Time Limit: 1000 MS    Memory Limit: 32768 KB

Description
Now lmh has already written a new GTP, he know how to play the broken chord by right hand. But as for the left hand chords, he can’t play all chords.So after he gets a new chord by random number programme, he finds a problem-- he can’t sing this song because his ability is not enough. But GTP is written, he doesn’t want to give up. Can you tell him how long can he sing continuously?

lmh is foolish. Even if he grasps a rhythm, such as ABCD, he only can play ABCD fluently, BCBC or ABCDABCD he can’t play it fluently.But as for BC, he can play it and just ignore A and D.

The guitar have a lot of the left chords. lmh just knows part of it, including C, Dm, Em, Am, F, G, D7, E, D, A, A7, Bm, B7, C7, G7, Dm7, Fmaj7, Asus4. This problem just need to deal with these chords.


Input
Input contains multiple test cases. Each test case contains two strings, each string will have at most 100000 characters.First string means the rhythm which lmh has grasped. Second string means a new rhythm by lmh’s random programme.


Output
A number means the biggest length which lmh can play.
(If he can’t play, output 0).


Sample Input
CAmFG
CAmFGCAmFG
AGAsus4D
GAsus4
B7G7
B7G7B7G7B7G7
AmFmaj7C7Dm7C7

C7Dm7C7Dm7C7


Sample Output
4
2
2

3


    除了图论Java大数,字符串在这两场比赛中也没出现过(上次的E题不算,都手算出来的......)所以当然要愉快的补一道字符串的题了~

    题意也不难懂,就是说给出两行字符串,第一行是lmh会弹的和弦,第二行是歌曲的和弦,问lmh弹这首歌最长能弹多长。但是如果lmh会ABCD,对于ABCDABCD他只能弹ABCD,对于BCBC他只能弹BC,就是说范围只能在第一行字符串中,换句话说就是求这两个字符串的最长公共子串。不过为了让这个题更恶心,我让这两个字符串的组成部分只包括C, Dm, Em, Am, F, G, D7, E, D, A, A7, Bm, B7, C7, G7, Dm7, Fmaj7, Asus4这些和弦。

    直接在网上套用了一个后缀数组的板子,然后把这些和弦都转化一下变成比如JKL这样没用过的单字符就方便比较了(表示我自己敲了一长串的for循环,一看阳敲的代码直接一个map解决了......好吧喜闻乐见的我200行代码别人50行)

    下面AC代码:

#include
#include
#include
#include
using namespace std;
int sint[200005];
int t1[200005],t2[200005],x[200005];
int c[200005],sa[200005],ran[200005],height[200005];
char s1[200005],s[200005];
int len1;

void build_sa(int *sint,int n,int m)
{
    int i,*x=t1,*y=t2,k;
    for(i=0;i=0;i--) sa[--c[x[i]]]=i;
    for(k=1;k<=n;k<<=1)
    {
        int p=0;
        for(i=n-k;i=k) y[p++]=sa[i]-k;
        for(i=0;i=0;i--)  sa[--c[x[y[i]]]]=y[i];
        swap(x,y);
        p=1;
        x[sa[0]]=0;
        for(i=1;i=n)
            break;
        m=p;
    }
}

void getheight(int n)
{
    int i,j,k=0;
    for(i=0;ians&&((sa[i-1]=len1)||(sa[i-1]>=len1&&sa[i]

你可能感兴趣的:(SDNU)