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. 用MPI进行分布式内存编程(1)

    <并行程序设计导论>第三章部分程序 程序3.1运行实例 #include<stdio.h> #include<string.h> #include<mpi.h ...

  2. Chrome简洁高效管理下载项

    每次要查看下载记录时,Chrome新建下载标签页的速度能让我抓狂 之前用的 Chrono 界面太过传统,而且还不能点击打开.所以一直在寻找好用的下载管理插件,经过多次在拓展商城搜索比对,找到了这款拓展 ...

  3. 方法解析之Method与ConstMethod介绍

    HotSpot通过Method与ConstMethod来保存方法元信息. 1.Method Method没有子类,定义在method.hpp文件中,其类继承关系如下图: Method用于表示一个Jav ...

  4. leetcode刷题笔记-1. 两数之和(java实现)

    题目描述 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但是,数组中同一个元素不能使 ...

  5. C#算法设计排序篇之07-希尔排序(附带动画演示程序)

    希尔排序(Shell's Sort) 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/687 访问. 希尔排序是插入排序的 ...

  6. C#LeetCode刷题之#268-缺失数字(Missing Number)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4056 访问. 给定一个包含 0, 1, 2, ..., n 中  ...

  7. Spring——IOC(控制反转)与DI(依赖注入)

    IOC与DI的理解及使用 控制反转IOC(Inversion of Control)是一种设计思想,DI(依赖注入)是实现IOC的一种方法.在没有IOC的程序中,我们使用面向对象编程,对象的创建于对象 ...

  8. C++ Templates (1.2 模板实参推断 Template Argument Deduction)

    返回完整目录 目录 1.2 模板实参推断 Template Argument Deduction 1.2 模板实参推断 Template Argument Deduction 当调用函数模板(如max ...

  9. ovs 删除流表 指定 actions 中字段

    例: ovs-ofctl del-flows br-int in_port=100,out_group=100 -O openflow13 ovs-ofctl del-flows br-int in_ ...

  10. 谱聚类的python实现

    什么是谱聚类? 就是找到一个合适的切割点将图进行切割,核心思想就是: 使得切割的边的权重和最小,对于无向图而言就是切割的边数最少,如上所示.但是,切割的时候可能会存在局部最优,有以下两种方法: (1) ...