hdu6570Wave (暴力求解)
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.
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.
1 2 1 3 2
#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 (暴力求解)的更多相关文章
- POJ 1562(L - 暴力求解、DFS)
油田问题(L - 暴力求解.DFS) Description The GeoSurvComp geologic survey company is responsible for detecting ...
- 逆向暴力求解 538.D Weird Chess
11.12.2018 逆向暴力求解 538.D Weird Chess New Point: 没有读好题 越界的情况无法判断,所以输出任何一种就可以 所以他给你的样例输出完全是误导 输出还搞错了~ 输 ...
- 隐型马尔科夫模型(HMM)向前算法实例讲解(暴力求解+代码实现)---盒子模型
先来解释一下HMM的向前算法: 前向后向算法是前向算法和后向算法的统称,这两个算法都可以用来求HMM观测序列的概率.我们先来看看前向算法是如何求解这个问题的. 前向算法本质上属于动态规划的算法,也就是 ...
- 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 ...
- <字符串匹配>KMP算法为何比暴力求解的时间复杂度更低?
str表示文本串,m表示模式串; str[i+j] 和 m[j] 是正在进行匹配的字符; KMP的时间复杂度是O(m+n) , 暴力求解的时间复杂度是O(m*n) KMP利用了B[0:j]和A[i ...
- HDU 4462 Scaring the Birds (暴力求解,二进制法)
题意:给定一个 n*n的矩阵,在一些位置放上稻草人,每个稻草人的范围是一定,问你最少几个能覆盖整个矩阵. 析:稻草人最多才10个,所以考虑暴力,然后利用二进制法,很容易求解,并且时间很少0ms,注意有 ...
- ZOJ 2856 Happy Life 暴力求解
因为是Special Judge 的题目,只要输出正确答案即可,不唯一 暴力力求解, 只要每次改变 happiness 值为负的人的符号即可. 如果计算出当前人的 happiness 值为负,那么将其 ...
- (暴力求解)Encoding HDU1020
Encoding 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1020 Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 2601An easy problem-素数的运用,暴力求解
id=17433" target="_blank" style="color:blue; text-decoration:none">An ea ...
随机推荐
- [2019杭电多校第七场][hdu6656]Kejin Player
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6656 题意为从i级花费a元有p的概率升到i+1级,有1-p的概率降到x级(x<i),查询从L级升 ...
- .net AutoMapper(对象与对象之间的映射器) 的简单使用
1.注册 /// <summary> /// AutoMapper 注册 /// </summary> public class AutoMapperConf ...
- 正则表达式RegExp对象
3.1 正则表达式对象的创建方式 字面量的方式 var patt = /匹配规则/修饰符; / --> 边界的意思 new关键字 var patt = new RegExp( ...
- 安装webpack的流程及注意事项
1)webpack依赖于node.js(node.js使用npm安装我们所依赖的js包) 2)安装npm(npm 全称是Node Package Manager,他是node包管理和分发工具) 3)通 ...
- ReentrantReadWriteLock实现原理
在java并发包java.util.concurrent中,除了重入锁ReentrantLock外,读写锁ReentrantReadWriteLock也很常用.在实际开发场景中,在使用共享资源时,可能 ...
- python pip安装模块报错 "Can't connect to HTTPS URL because the SSL module is not available."
在升级python版本为3.6之后,pip安装模块报错. 报错信息如图: 原因是系统自带的openssl版本与python3的版本不匹配,所以这里只要升级openssl版本就可以解决问题. yum - ...
- postgresql windows 服务启动失败
1命令行 启动服务 pg_ctl -D "C:\Program Files\PostgreSQL\9.1\data" start 2 查看状态 pg_ctl -D "C: ...
- simrank python实现
1.数据 pc,hp.com pc,hp.com pc,hp.com pc,hp.com pc,hp.com pc,hp.com pc,hp.com pc,hp.com pc,hp.com pc,hp ...
- bzoj3991 [SDOI2015]寻宝游戏 树链的并
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=3991 题解 貌似这个东西叫做树链的并,以前貌似写过一个类似的用来动态维护虚树. 大概就是最终的 ...
- man LVCREATE
LVCREATE(8) LVCREATE(8) NAME/名称 lvcreat ...