Problem Description
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.
 
Input
The 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.
 
Output
Print the length of the longest "wave" subseries.
 
Sample Input
5 3
1 2 1 3 2
 
Sample Output
4
 
Source
 
中文题意:给你两个数n,c;接下来会再给你n个数在[1,c]之间;
问你从其中找出一个子序列,使得奇数的位置所有的数都相等,所有偶数的位置也相等,但奇数与偶数位置的数不能相等;
这个奇数位置,偶数位置是相对于你选出来的子序列,在子序列中的位置
 
思路:暴力求解:记下n个数中重复出现数的个数,然后每两个组合,查找这两个数可以组成的最长子序列;
 
AC624ms:

#include<iostream>
#include<cstdio>
using namespace std;
int num[100005];
struct node{
int number,quanlity;//第一个存储表示的是哪一个数,第二个表示这个数的个数
}d[105];
int cmp(struct node x,struct node y){
return x.quanlity>y.quanlity;
}
int main(){
int n,c;
scanf("%d%d",&n,&c);
for(int i=0;i<=100;i++)
d[i].quanlity=0,d[i].number=i;
for(int i=0;i<n;i++)
scanf("%d",&num[i]),d[num[i]].quanlity++;
/* for(int i=0;i<c;i++)
printf("%d %d\n",d[i].number,d[i].quanlity);*/
int maxn=0;
for(int i=0;i<c-1;i++){
for(int ii = i+1;ii<c;ii++){
int s = 1 , x = d[i].number , y = d[ii].number , mm , j;
for(j=0;j<n;j++){if(num[j]==x||num[j]==y) {mm=num[j];break;}}
for(;j<n;j++){
if(num[j]==x||num[j]==y){
if(num[j]!=mm) s++,mm=num[j];
}
}
if(s>maxn) maxn=s;
}
}
printf("%d\n",maxn);
return 0;
}

//10 4
//1 4 3 1 3 1 2 2 1 2

最新文章

  1. Oracle 安装及其遇到的问题
  2. cvKMeans2函数用法概述
  3. 网页上的表格数据table
  4. 利用CSS的@font-face属性 在网页中嵌入字体
  5. CF 191C Fools and Roads lca 或者 树链剖分
  6. Tomcat 系统架构与设计模式,第 2 部分: 设计模式分析(转载)
  7. IIS7/8 HTTP Error 500.19 错误 0x80070021
  8. PostgreSQL的AnynonArray的例子
  9. Java之循环语句练习1
  10. 关于scrollTop的那些事
  11. 【每天一个Linux命令】13. Linux中whereis命令的用法
  12. Hadoop获得先进的步步高(四)-试Hadoop
  13. amaze UI 笔记 - CSS
  14. Flask--路由, 配置, 蓝图
  15. webpack学习笔记--配置总结
  16. jQuery 常用效果
  17. Codeforces 862D. Mahmoud and Ehab and the binary string (二分)
  18. 分页---Vue+.net+bootstrap实现
  19. Java 中request.getInputStream()和BufferedReader 和 InputStreamReader 用法
  20. div+css经典三行两列布局

热门文章

  1. [luogu4768] [NOI2018] 归程 (Dijkstra+Kruskal重构树)
  2. shutdown的几种方法和利弊
  3. H-Updating a Dictionary (模拟)
  4. iOS开发-retain/assign/strong/weak/copy/mutablecopy/autorelease区别
  5. 【vue】父子组件间通信----传函数
  6. pgtclsh -- PostgreSQL TCLshell 客户端
  7. Linux基础之输入输出
  8. MYSQL学习笔记——数据库范式及MYSQL优化整体思路
  9. CreateProcessAsUser 服务调用
  10. CSS3选择器 ::selection选择器