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+;
typedef long long ll;
using namespace std;
vector<int>vec[];
int main()
{
int n,c;
cin>>n>>c;
int x;
for(int t=;t<=n;t++)
{
scanf("%d",&x);
vec[x].push_back(t);
}
int ans=;
for(int t=;t<=c;t++)
{
for(int j=;j<=c;j++)
{
if(t==j)continue;
int s1=vec[t].size();
int s2=vec[j].size();
int st1=,st2=;
int temp=;
int sum=;
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\n",ans);
return ;
}
												

HDU - 6570 - Wave(暴力)的更多相关文章

  1. HDU 5510 Bazinga 暴力匹配加剪枝

    Bazinga Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5510 ...

  2. HDU 5522 Numbers 暴力

    Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5522 ...

  3. hdu 5077 NAND(暴力打表)

    题目链接:hdu 5077 NAND 题目大意:Xiaoqiang要写一个编码程序,然后依据x1,x2,x3的值构造出8个字符.如今给定要求生成的8个字符.问 说Xiaoqiang最少要写多少行代码. ...

  4. hdu 5726 GCD 暴力倍增rmq

    GCD/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5726 Description Give you a sequence ...

  5. hdu 4291(矩阵+暴力求循环节)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4291 思路:首先保留求出循环节,然后就是矩阵求幂了. #include<iostream> ...

  6. HDU 4462(暴力枚举)

    因为题目当中的k比较小k <= 10,所以可以直接枚举,题目里面由两个trick, 一个是如果每个点都可以放稻草人的话,那么答案是0, 另外一个就是如果可以放稻草人的点不用被照到.知道了这两个基 ...

  7. hdu 4499 Cannon(暴力)

    题目链接:hdu 4499 Cannon 题目大意:给出一个n*m的棋盘,上面已经存在了k个棋子,给出棋子的位置,然后求能够在这种棋盘上放多少个炮,要求后放置上去的炮相互之间不能攻击. 解题思路:枚举 ...

  8. hdu 4277 USACO ORZ (暴力+set容器判重)

    USACO ORZ Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. BestCoder Round #50 (div.1) 1002 Run (HDU OJ 5365) 暴力枚举+正多边形判定

    题目:Click here 题意:给你n个点,有多少个正多边形(3,4,5,6). 分析:整点是不能构成正五边形和正三边形和正六边形的,所以只需暴力枚举四个点判断是否是正四边形即可. #include ...

随机推荐

  1. 使用Android Studio创建模拟器,安装配置Android SDK

    Android Studio 一个写安卓APP应用的代码编辑器之类的?嗯,应该是... 这里只是需要用到里面的AVD Manager 创建安卓模拟器(也可以用mumu类的安卓模拟器):SDK Mana ...

  2. python4.5实用内置模块

    #引入urllib百度网页的数据爬取 from urllib import request url="http://www.baidu.com"data=request.urlop ...

  3. python1.3集合知识点:

    #定义集合:{},集合是只有key没有value的字典,集合内元素不能重复!a={1,2,3,4,5,6}#列表转换成集合b=set([1,2,3,4,5])print(a,b) #集合对列表进行去重 ...

  4. mqtt第一次接触

    一.接触的原因 公司最近要求接手关于系统集成道闸的部分,其中系统和第三方系统是通过mqtt进行交互的.所以提前了解一下mqtt的基础概念. 二.mqtt的基本概念 1. mqtt的定义 Message ...

  5. 薪资高,福利好,会Python的人就是这么豪横!

    很多人可能会有这样的疑问,数据分析Excel挺强大的,会Excel就行,为什么还要去学python? 是的,Excel和python对于数据分析而言,这两者都只是不同的工具而已. 很多人学习pytho ...

  6. 《Java核心技术(卷1)》笔记:第12章 并发

    线程 (P 552)多进程和多线程的本质区别:每一个进程都拥有自己的一整套变量,而线程共享数据 (P 555)线程具有6种状态: New(新建):使用new操作符创建线程时 Runnable(可运行) ...

  7. ElasticSearch 7.8.1 从入门到精通

    学前导读 ElasticSearch对电脑配置要求较高,内存至少4G以上,空闲2G内存,线程数4018+ 学习的时候,推荐将ElasticSearch安装到Linux或者mac上,极度不推荐装Wind ...

  8. Visual Studio 2017版本15.9现在可用

    本文转自 https://blogs.msdn.microsoft.com/visualstudio/2018/11/19/visual-studio-2017-version-15-9-now-av ...

  9. 浅谈:C#中的非泛型集合

    1.首先:ArrayList:非泛型集合 List:泛型集合 集合跟数组比较我们更容易理解.数组:1,长度固定2,数据类型预先声明 集合:1,长度可变2,数据类型预先声明的为泛型集合,数据类型不限定为 ...

  10. 精讲RestTemplate第7篇-自定义请求失败异常处理

    本文是精讲RestTemplate第7篇,前篇的blog访问地址如下: 精讲RestTemplate第1篇-在Spring或非Spring环境下如何使用 精讲RestTemplate第2篇-多种底层H ...