浙江省赛之Singing Everywhere
题目: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的更多相关文章
- ZOJ 3879 Capture the Flag 15年浙江省赛K题
每年省赛必有的一道模拟题,描述都是非常的长,题目都是蛮好写的... sigh... 比赛的时候没有写出这道题目 :( 题意:首先输入4个数,n,q,p,c代表有n个队伍,q个服务器,每支队伍的初始分数 ...
- The 13th Zhejiang Provincial Collegiate Contest(2016年浙江省赛)
前4道水题就不说了,其中我做了C题,1Y,小心仔细写代码并且提交之前得确认无误后提交才能减少出错率. 结果后面2题都由波神做掉,学长带我们飞~ 终榜 官方题解 ZOJ 3946 Highway ...
- ZOJ 3872 Beauty of Array DP 15年浙江省赛D题
也是一道比赛时候没有写出来的题目,队友想到了解法不过最后匆匆忙忙没有 A 掉 What a pity... 题意:定义Beauty数是一个序列里所有不相同的数的和,求一个序列所有字序列的Beauty和 ...
- (2017浙江省赛E)Seven Segment Display
Seven Segment Display Time Limit: 2 Seconds Memory Limit: 65536 KB A seven segment display, or ...
- 浙江省赛 C What Kind of Friends Are You?
思路:一开始考虑n个朋友可以有c种可能,根据回答的问题,如果是yes那么可以确定一些朋友的范围,将原本不在这个范围内的删除即可:如果是"no",说明这些朋友都应该被删除,那么最后看 ...
- 2019浙江省赛B zoj4101 Element Swapping(推公式)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=6003 题意 \(数组a通过交换一对数字,得到了b数组,给出x=\sum^n_{ ...
- 2019浙江省赛K zoj4110 Strings in the Pocket(manachar)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=6012 题意 给你两个串,可以翻转a串的一个区间,问有多少对l,r使得翻转后的a ...
- 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 ...
- 浙江省赛 ZOJ4029
Now Loading!!! Time Limit: Second Memory Limit: KB DreamGrid has integers . DreamGrid also has queri ...
随机推荐
- Mysql 多表数据拼接插入及子查询结果集随机取一条
最近遇到一个测试数据的需求,需要往一个表中插入4个来源的数据. 往orders 表中插入 来自 sql_person cm_user_car_model cm_sp_product_new 部分固定数 ...
- Galaxy2D Game Engine 4.2 开发版发布
Update: ◆删除Graph_GetRenderTarget()函数,添加Graph_CopyBackBuffer()/Graph_CopyRanderTarget()函数 ◆Graph_EndS ...
- 基于Python的设计模式简述
结构梳理>>> 第一部分: 创建型模式 工厂模式 工厂方法 抽象工厂 建造者模式 原型模式 单例模式 第二部分: 结构型模式 适配器模式 修饰器模式 外观模式 享元模式 模型-视图- ...
- [STM32F103]PWM输入捕获配置
l 初始化定时器和通道对应IO的时钟. l 初始化IO口,模式为输入: GPIO_Init(); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //PA0 ...
- gradle项目
gradle构建web项目 0.安装gradle http://services.gradle.org/distributions/ 下载对应版本:gradle-5.2.1-bin.zip 解压到自定 ...
- hashcode()和equals()
一.equal()方法 Object类中equals()方法实现如下: public boolean equals(Object obj) { return (this == obj); } 通过该实 ...
- Java 高级框架——Mybatis(一)
一, SQl复习 a,数据库SQL命令 创建数据库并指定编码 Create database 数据库名 default character set utf8 create database ssm d ...
- js小技巧总结
js小技巧总结 1.Array.includes条件判断 function test(fruit) { const redFruits = ["apple", "stra ...
- arc 097 E - Sorted and Sorted
E - Sorted and Sorted Time limit : 2sec / Memory limit : 1024MB Score : 600 points Problem Statement ...
- HDU1671 Phone List
Phone List Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Probl ...