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

hdu6570Wave (暴力求解)的更多相关文章

  1. POJ 1562(L - 暴力求解、DFS)

    油田问题(L - 暴力求解.DFS) Description The GeoSurvComp geologic survey company is responsible for detecting ...

  2. 逆向暴力求解 538.D Weird Chess

    11.12.2018 逆向暴力求解 538.D Weird Chess New Point: 没有读好题 越界的情况无法判断,所以输出任何一种就可以 所以他给你的样例输出完全是误导 输出还搞错了~ 输 ...

  3. 隐型马尔科夫模型(HMM)向前算法实例讲解(暴力求解+代码实现)---盒子模型

    先来解释一下HMM的向前算法: 前向后向算法是前向算法和后向算法的统称,这两个算法都可以用来求HMM观测序列的概率.我们先来看看前向算法是如何求解这个问题的. 前向算法本质上属于动态规划的算法,也就是 ...

  4. BestCoder Round #79 (div.2)-jrMz and angles,,暴力求解~

    jrMz and angle       Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536/65536 K (Java/Other ...

  5. <字符串匹配>KMP算法为何比暴力求解的时间复杂度更低?

    str表示文本串,m表示模式串; str[i+j] 和 m[j] 是正在进行匹配的字符; KMP的时间复杂度是O(m+n)  ,  暴力求解的时间复杂度是O(m*n) KMP利用了B[0:j]和A[i ...

  6. HDU 4462 Scaring the Birds (暴力求解,二进制法)

    题意:给定一个 n*n的矩阵,在一些位置放上稻草人,每个稻草人的范围是一定,问你最少几个能覆盖整个矩阵. 析:稻草人最多才10个,所以考虑暴力,然后利用二进制法,很容易求解,并且时间很少0ms,注意有 ...

  7. ZOJ 2856 Happy Life 暴力求解

    因为是Special Judge 的题目,只要输出正确答案即可,不唯一 暴力力求解, 只要每次改变 happiness 值为负的人的符号即可. 如果计算出当前人的 happiness 值为负,那么将其 ...

  8. (暴力求解)Encoding HDU1020

    Encoding 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1020 Time Limit: 2000/1000 MS (Java/Others)    ...

  9. HDU 2601An easy problem-素数的运用,暴力求解

    id=17433" target="_blank" style="color:blue; text-decoration:none">An ea ...

随机推荐

  1. 单调栈 && 洛谷 P2866 [USACO06NOV]糟糕的一天Bad Hair Day(单调栈)

    传送门 这是一道典型的单调栈. 题意理解 先来理解一下题意(原文翻译得有点问题). 其实就是求对于序列中的每一个数i,求出i到它右边第一个大于i的数之间的数字个数c[i].最后求出和. 首先可以暴力求 ...

  2. Vue.js状态管理模式 Vuex

    vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化. 安装.使用 vuex 首先我们在 vue. ...

  3. ElasticSearch 7.x 默认不在支持指定索引类型

    原文:ElasticSearch 7.x 默认不在支持指定索引类型 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://bl ...

  4. SSM商城系统开发笔记-配置01-web.xml

    先占坑 慢慢填, 商城系统使用主体框架:Spring + Spring MVC + Mybatis 其他框架: 日志: slf4j + logback <!DOCTYPE web-app PUB ...

  5. Jquery WEUI 滚动加载(infinite)不触发

    源代码:(1.0.1版本) Infinite.prototype.scroll = function() { var container = this.container; var offset = ...

  6. Lamabda Where Select Find First等区别

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...

  7. Linux架构之Nginx Web基础1

    第41章 Nginx Web基础入门 41.1 Nginx部署 41.1.1 Nginx的安装方式   源码编译 官方仓库 epel仓库 优点 规范 安装简单 安装简单   便于管理 配置易读   缺 ...

  8. Car的旅行路线(Floyd+模拟)

    题目地址 贼鸡儿猥琐的一道题 好在数据不毒瘤,而且Floyd就OK了. 这道题的难点在于 建图,也很考验模拟能力,需要十分的有耐心. 建图 题目中告诉了我们一个矩形的三个点 我们在平面直角坐标系中随便 ...

  9. shelve模块 xml模块

    # import shelve# f=shelve.open('db.shl')# # f['stu1']={'name':'alex1','age':28}# # f['stu2']={'name' ...

  10. JS原型和原型链(3)

    构造函数创建对象: function Person() { } var person = new Person(); person.name = 'Kevin'; console.log(person ...