• HDU


    Avin is studying series. A series is called "wave" if the following conditions are satisfied: 
    1) It contains at least two elements; 
    2) All elements at odd positions are the same; 
    3) All elements at even positions are the same; 
    4) Elements at odd positions are NOT the same as the elements at even positions. 
    You are given a series with length n. Avin asks you to find the longest "wave" subseries. A subseries is a subsequence of a series.

    InputThe first line contains two numbers n, c (1 ≤ n ≤ 100, 000, 1 ≤ c ≤ 100). The second line contains n integers whose range is [1, c], which represents the series. It is guaranteed that there is always a "wave" subseries.OutputPrint the length of the longest "wave" subseries.Sample Input

    
    
    5 3
    1 2 1 3 2

    Sample Output

    4

    把任意两个数的位置存一下 然后暴力枚举进行依次存放即可
    代码:
    #include<cstdio>
    #include<iostream>
    #include<algorithm>
    #include<cstring>
    #include<queue>
    #include<stack>
    #include<set>
    #include<map>
    #include<vector>
    #include<cmath>
    
    const int maxn=1e5+5;
    typedef long long ll;
    using namespace std;
    vector<int>vec[105];
    int main()
    {
        int n,c;
        cin>>n>>c;
        int x;
        for(int t=1;t<=n;t++)
        {
            scanf("%d",&x);
            vec[x].push_back(t);
        }
        int ans=0;
        for(int t=1;t<=c;t++)
        {
            for(int j=1;j<=c;j++)
            {
                if(t==j)continue;
                int s1=vec[t].size();
                int s2=vec[j].size();
                int st1=0,st2=0;
                int temp=0;
                int sum=0;
                for(;;)
                {
                    while(st1<s1&&vec[t][st1]<temp)
                    {
                        st1++;
                    }
                    if(st1==s1)
                    {
                        break;
                    }
                    temp=vec[t][st1];
                    sum++;
                    while(st2<s2&&vec[j][st2]<temp)
                    {
                        st2++;
                    }
                    if(st2==s2)
                    {
                        break;
                    }
                    sum++;
                    temp=vec[j][st2];
                }
                ans=max(ans,sum);
            }
        }
        printf("%d
    ",ans);
        return 0;
    }


  • 相关阅读:
    【转】QT QTableWidget 用法总结
    【转】OpenGL光照处理
    VTK 使用笔记
    【转】toggled 和 trigger 的区别
    白噪声 高斯白噪声
    离线 截图
    【转】 什么是句柄?为什么会有句柄?HANDLE
    VS 常用快捷键 整理
    【转】OpenCV 编程入门
    "This qt version uses an unsupported makefile generator (used: ,supported: MSVC.NET, MSBUILD)"
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/11224015.html
Copyright © 2020-2023  润新知