[POJ1743] Musical Themes music topic suffix array (you can also use hash + binary ~)

Source: Internet
Author: User

[POJ1743] Musical Themes music topic suffix array (you can also use hash + binary ~)

Question:

 

1829: Musical Themes music topic Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 42 Solved: 15
[Submit] [Status] [Web Board] Description

We use the sequence of N (1 <= N <= 5000) Notes to represent a piece of music. Each note is 1 .. an integer in the range of 88. Each number represents a key on the piano. Unfortunately, this way of representing the melody ignores the value of the note, but this programming task is about the pitch and has nothing to do with the value.

Many writers construct music around a recurring "topic. In our music representation, the "theme" is a subsequence of the whole sequence of notes. It must meet the following conditions:

  • It can contain at least five notes.
  • Repeated appearance in music (may be transferred, see below)
  • Duplicate topics cannot overlap.

    "Transpose" means that each note in the topic sequence is added or subtracted from the same integer.

    For a piece of music, calculate the longest topic length (that is, the number of notes ).

    Input

    The first line of the output file contains an integer N. Each line below (except the last line may be) contains 20 integers, indicating the sequence of notes. The last line may contain less than 20 notes.

    Output

    The output file must contain only one integer, that is, the length of the longest topic. If there is no topic in the music, 0 is output.

    Sample Input3025 27 30 34 39 45 52 60 69 69 60 52 45 39 34 30 26 22 1882 78 74 70 66 67 64 60 65 80 Sample Output5HINT

     

    In the example, the topic with a length of 5 is the last five notes in the first line of the input file and the first five notes in the second line.

     

    Source

    USACO

    Best Solution
    C C ++ Pascal
    NULL 80643. wyfcyx
    (0 ms, 1100KB, 2168B)
    21804. Ares
    (72 ms, 292KB, 561B)
    [Submit] [Status] [Web Board] Bytes Powered by LLQ .? 2012-2014 Changchun Jilin University attached high school Experimental School.

     

    Question:

    Ah, write an array with a suffix, and then divide it into groups based on the height during the binary check, so that each segment can satisfy the height long enough to scan it again, if there is no overlap between the farthest two (sa difference is large enough), return 1...

     

    Code:

     

    #include 
       
        #include 
        
         #include 
         
          #include #define N 21000using namespace std;int s[N];int sa[N],rank[N],h[N],n,m,len;int cnt[N],val[N],stk[N],_val[N],top;bool issame(int a,int b,int hl){return val[a]==val[b]&&((a+hl>=len&&b+hl>=len)||(a+hl
          
           =0;i--)sa[--cnt[val[i]]]=i;for(k=1;;k++){top=0,hl=1<<(k-1);for(i=0;i
           
            =len)stk[top++]=sa[i];for(i=0;i
            
             =hl)stk[top++]=sa[i]-hl;for(i=0;i
             
              =0;i--)sa[--cnt[val[stk[i]]]]=stk[i];for(lim=i=0;i
              
               mid)return 1;}return 0;}int main(){//freopen("test.in","r",stdin);int i,j,k;scanf("%d",&len);scanf("%d",&s[0]);for(i=1;i
               
                >1;if(check(mid))l=mid;else r=mid-1;}if(ans>=4)printf("%d\n",ans+1);else puts("0");return 0;}
               
              
             
            
           
          
         
        
       


     

     

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.