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

  1.  
  1. 5 3
  2. 1 2 1 3 2

Sample Output

  1. 4
  2.  
  3. 把任意两个数的位置存一下 然后暴力枚举进行依次存放即可
    代码:
  1. #include<cstdio>
  2. #include<iostream>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<queue>
  6. #include<stack>
  7. #include<set>
  8. #include<map>
  9. #include<vector>
  10. #include<cmath>
  11.  
  12. const int maxn=1e5+;
  13. typedef long long ll;
  14. using namespace std;
  15. vector<int>vec[];
  16. int main()
  17. {
  18. int n,c;
  19. cin>>n>>c;
  20. int x;
  21. for(int t=;t<=n;t++)
  22. {
  23. scanf("%d",&x);
  24. vec[x].push_back(t);
  25. }
  26. int ans=;
  27. for(int t=;t<=c;t++)
  28. {
  29. for(int j=;j<=c;j++)
  30. {
  31. if(t==j)continue;
  32. int s1=vec[t].size();
  33. int s2=vec[j].size();
  34. int st1=,st2=;
  35. int temp=;
  36. int sum=;
  37. for(;;)
  38. {
  39. while(st1<s1&&vec[t][st1]<temp)
  40. {
  41. st1++;
  42. }
  43. if(st1==s1)
  44. {
  45. break;
  46. }
  47. temp=vec[t][st1];
  48. sum++;
  49. while(st2<s2&&vec[j][st2]<temp)
  50. {
  51. st2++;
  52. }
  53. if(st2==s2)
  54. {
  55. break;
  56. }
  57. sum++;
  58. temp=vec[j][st2];
  59. }
  60. ans=max(ans,sum);
  61. }
  62. }
  63. printf("%d\n",ans);
  64. return ;
  65. }
  1.  

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. ORACLE常用语句:

    ORACLE常用语句: 1.首先,创建(新)用户: create user username identified by password; username:新用户名的用户名 password: 新 ...

  2. python6.2类的封装

    class Card(object): def __init__(self,num,pwd,ban): self.num=num#卡号 self.pwd=pwd#密码 self.__ban=ban#余 ...

  3. Springboot2.x整合logback slf4j

    Springboot项目的pom里引入的parent <parent> <groupId>org.springframework.boot</groupId> &l ...

  4. Catalina 默认使用zsh了,你可习惯

    zsh 成为默认 shell 淘汰掉我的旧MBP换新后,欢天喜地打开Terminal,感觉有点不对,提示符什么时候变成了 %. 查询了一些资料发现,原来在2019年WWDC期间,苹果推出了macOS ...

  5. 我能想到的最浪漫的Java网络教程之Socket,三步到位!!!

    简说 如果要使用Java中的TCP/IP通过网络连接到服务器,则需要创建一个java.net.Socket对象以连接到服务器.如果使用JavaNIO,则还可以在JavaNIO中创建SocketChan ...

  6. 2020-07-05:tcp和udp的区别和应用场景。如何实现断点续传?

    福哥答案2020-07-05: 区别:1.可靠性:tcp可靠.udp不可靠.2.连接性:tcp面向连接.udp无连接.3.报文:tcp字节流.udp面向报文.4.传输效率:tcp低.udp高.5.多点 ...

  7. Jdk1.8下的HashMap源码分析

    目录结构 一.面试常见问题 二.基本常量属性 三.构造方法 四.节点结构        4.1 Node类        4.2.TreeNode 五.put方法        5.1 key的has ...

  8. Kafka 为什么快

    Kafka 为什么能那么快 | Kafka高效读写数据的原因 无论 kafka 作为 MQ 也好,作为存储层也罢,无非就是两个功能(好简单的样子),一是 Producer 生产的数据存到 broker ...

  9. Windows Server2008RFTP隔离账户的搭建

    Step1:添加用户 打开DOS命令, net user net user u1 123.com /add net user u2 123.com /add Step2:创建文件夹 Step3:修改用 ...

  10. Hbase写入流程图

    写入流程图