题目:http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5996

方法:

在大佬的指导下完成。

寻找峰值,找到一共k个峰值。

遍历:使a[0]=231,a[n+1]=231(0xfffffff),从第一个数开始,判断它的存在有多少个峰值 yu,它被去掉后有多少个峰值xz  (这时不是找出所有的峰值,而是看(a[i-1],a[i],a[i+1])这三个数中有几个是峰值就可以)。

q存储着上一次的yu-xz;也就是去掉上一个数可以减少多少个峰值,所以最终的p和q的最大值就是可以减少的最多的峰值。

原来的峰值个数-减少的峰值个数=结果。

#include<iostream>
#include<string>
using namespace std;
int a[];
int main()
{
int t;
cin >> t;
while (t--)
{
int n,k=,q=,p=; cin >> n;
a[n + ] = 0x7fffffff;
a[] = 0x7fffffff;
for (int i = ; i <= n; i++)
cin >> a[i];
for (int i = ; i < n; i++)
{
p = ;
int yl = , xz = ;
if (a[i] > a[i - ] && a[i] > a[i + ])
{
yl++;
k++;
}
if (a[i - ] > a[i] && a[i - ] > a[i - ])
{
yl++;
}
if (a[i + ] > a[i] && a[i + ] > a[i + ])
{
yl++;
}
if (a[i - ] > a[i+] && a[i - ] > a[i - ])
{
xz++;
}
if (a[i + ] > a[i-] && a[i + ] > a[i + ])
{
xz++;
}
p = yl - xz;
if (p > q)
q = p; }
cout << k - q << endl;;
} getchar();
getchar();
return ;
}

浙江省赛之Singing Everywhere的更多相关文章

  1. ZOJ 3879 Capture the Flag 15年浙江省赛K题

    每年省赛必有的一道模拟题,描述都是非常的长,题目都是蛮好写的... sigh... 比赛的时候没有写出这道题目 :( 题意:首先输入4个数,n,q,p,c代表有n个队伍,q个服务器,每支队伍的初始分数 ...

  2. The 13th Zhejiang Provincial Collegiate Contest(2016年浙江省赛)

      前4道水题就不说了,其中我做了C题,1Y,小心仔细写代码并且提交之前得确认无误后提交才能减少出错率. 结果后面2题都由波神做掉,学长带我们飞~ 终榜 官方题解   ZOJ 3946 Highway ...

  3. ZOJ 3872 Beauty of Array DP 15年浙江省赛D题

    也是一道比赛时候没有写出来的题目,队友想到了解法不过最后匆匆忙忙没有 A 掉 What a pity... 题意:定义Beauty数是一个序列里所有不相同的数的和,求一个序列所有字序列的Beauty和 ...

  4. (2017浙江省赛E)Seven Segment Display

    Seven Segment Display Time Limit: 2 Seconds      Memory Limit: 65536 KB A seven segment display, or ...

  5. 浙江省赛 C What Kind of Friends Are You?

    思路:一开始考虑n个朋友可以有c种可能,根据回答的问题,如果是yes那么可以确定一些朋友的范围,将原本不在这个范围内的删除即可:如果是"no",说明这些朋友都应该被删除,那么最后看 ...

  6. 2019浙江省赛B zoj4101 Element Swapping(推公式)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=6003 题意 \(数组a通过交换一对数字,得到了b数组,给出x=\sum^n_{ ...

  7. 2019浙江省赛K zoj4110 Strings in the Pocket(manachar)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=6012 题意 给你两个串,可以翻转a串的一个区间,问有多少对l,r使得翻转后的a ...

  8. 140 - The 12th Zhejiang Provincial Collegiate Programming Contest(浙江省赛2015)

      Ace of Aces Time Limit: 2 Seconds      Memory Limit: 65536 KB There is a mysterious organization c ...

  9. 浙江省赛 ZOJ4029

    Now Loading!!! Time Limit: Second Memory Limit: KB DreamGrid has integers . DreamGrid also has queri ...

随机推荐

  1. 结合源码浅谈Spring容器与其子容器Spring MVC 冲突问题

    容器是整个Spring 框架的核心思想,用来管理Bean的整个生命周期. 一个项目中引入Spring和SpringMVC这两个框架,Spring是父容器,SpringMVC是其子容器,子容器可以看见父 ...

  2. 3、redis使用场景

    现代高并发复杂系统面临的挑战 现代系统随着功能的复杂化,各种各样需求层出不穷,面对愈加复杂话的业务系统.越来越庞大的用户群体,以及用户对体验的要求越来越高,性能就变得更加重要. 抛开代码逻辑.服务器性 ...

  3. Flume概念与原理、与Kafka优势对比《转》

    https://blog.csdn.net/gyshun/article/details/79710534

  4. linux centos 中访问linux 共享文件方法

    mount -t cifs -o username="administrator",password="" //192.168.1.101/cp /mnt/nt ...

  5. Linux基本指令

    常用目录文件作用 - /    根目录 - /bin    命令保存目录(普通用户就可以读取的命令) - /boot    启动目录,启动相关文件 - /dev    设备文件保存目录 - /etc  ...

  6. LeetCode 86. Partition List 划分链表 C++

    Given a linked list and a value x, partition it such that all nodes less than x come before nodes gr ...

  7. 关于单元测试时加载spring-context.xml文件的问题

    在进行web开发的时候,通常我们都会使用Spring框架,使用spring容器管理java bean. 而spring的配置文件有时候放在classpath下面,有时候放在WEB-INF下面. 一般在 ...

  8. Python学习日记 --day2

    Python学习日记 --day2 1.格式化输出:% s d  (%为占位符 s为字符串类型 d为数字类型) name = input('请输入姓名') age = int(input('请输入年龄 ...

  9. Delphi Sysem.JSON 链式写法(转全能中间件)

    链式写法有很多优点:连贯.语意集中.简洁.一气呵成.可读性强.比如要把 3.1415926 中的 59 提取为一个整数:Pi.ToString().Substring(5,2).ToInteger() ...

  10. Vue相关文章

    1.新手向:Vue 2.0 的建议学习顺序 2.用webstorm搭建vue项目 3.vue-cli3.0项目结构