Singing Everywhere ZOJ - 4107
https://vjudge.net/problem/ZOJ-4107/origin
https://vjudge.net/contest/395635#problem/H
Baobao loves singing very much and he really enjoys a game called Singing Everywhere, which allows players to sing and scores the players according to their performance.
Consider the song performed by Baobao as an integer sequence $a_1, a_2,\dots,a_n$, where $a_i$ indicates the $i$-th note in the song. We say a note $a_k$ is a "voice crack" if $1 < k < n$, $a_{k-1} < a_k$ and $a_{k+1} < a_k$. The more voice cracks BaoBao sings, the lower score he gets.
To get a higher score, BaoBao decides to delete at most one note in the song. What's the minimum number of times BaoBao sings a voice crack after this operation?
Input
There are multiple test cases. The first line of the input contains an integer $T$ (about 100), indicating the number of test cases. For each test case:
The first line contains one integer $n$ ($1 \leq n \leq 10^{5}$), indicating the length of the song.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-2^{31} \leq a_i < 2^{31}$), indicating the song performed by BaoBao.
It's guaranteed that at most 5 test cases have $n > 100$.
Output
For each test case output one line containing one integer, indicating the answer.
Sample Input
3
6
1 1 4 5 1 4
7
1 9 1 9 8 1 0
10
2 1 4 7 4 8 3 6 4 7
Sample Output
1
0
2
Hint
For the first sample test case, BaoBao does not need to delete a note. Because if he deletes no note, he will sing 1 voice crack (the 4th note), and no matter which note he deletes, he will also always sing 1 voice crack.
For the second sample test case, BaoBao can delete the 3rd note, and no voice cracks will be performed. Yay!
For the third sample test case, BaoBao can delete the 4th note, so that only 2 voice cracks will be performed (4 8 3 and 3 6 4).
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iomanip>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <iterator>
#include <utility>
#include <sstream>
#include <limits>
#include <numeric>
#include <functional>
using namespace std;
#define gc getchar()
#define mem(a) memset(a,0,sizeof(a))
#define debug(x) cout<<"debug:"<<#x<<" = "<<x<<endl; #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef char ch;
typedef double db; const double PI=acos(-1.0);
const double eps=1e-6;
const int inf=0x3f3f3f3f;
const int maxn=1e5+10;
const int maxm=100+10;
const int N=1e6+10;
const int mod=1e9+7; ll a[100005] = {0};
int main()
{
int t = 0;
cin >> t;
while(t--)
{
int n = 0;
cin >> n;
for(int i = 0;i<n;i++)
{
cin >> a[i];
}
int mark = 0;
int counter = 0;
for(int i = 1;i<n-1;i++)
{
if(a[i]>a[i-1]&&a[i]>a[i+1])
{
counter += 1;
if( a[i-1] <= a[i-2] && a[i-1] <= a[i+1] && a[i+1] <= a[i+2]
|| a[i+1] <= a[i+2] && a[i+1] <= a[i-1] && a[i-1] <= a[i-2])
{
mark = 1;
}
if(a[i+2]>a[i+1] && a[i+2]>a[i+3] && a[i]==a[i+2])
{
mark = 2;
}
}
}
cout << counter - mark << endl;
}
return 0;
}
Singing Everywhere ZOJ - 4107的更多相关文章
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
- ZOJ Problem Set - 1049 I Think I Need a Houseboat
这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...
- ZOJ Problem Set - 1006 Do the Untwist
今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...
- ZOJ Problem Set - 1001 A + B Problem
ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...
- zoj 1788 Quad Trees
zoj 1788 先输入初始化MAP ,然后要根据MAP 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...
- ZOJ 1958. Friends
题目链接: ZOJ 1958. Friends 题目简介: (1)题目中的集合由 A-Z 的大写字母组成,例如 "{ABC}" 的字符串表示 A,B,C 组成的集合. (2)用运算 ...
- ZOJ
某年浙大研究生考试的题目. 题目描述: 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC. 是否AC的规则如下:1. zoj能AC:2. 若字符串形式为xzojx,则也能AC, ...
随机推荐
- L1-1、Prompt 是什么?为什么它能“控制 AI”?
*--Prompt 入门 L1-1 想象一下,你只需输入一句话,AI 就能自动为你写一篇文案.生成一份报告.甚至规划你的创业计划.这种"对话即编程"的背后魔法,就是 Prompt ...
- IDEA jrebel热部署插件破解-最新版
前言 JRebel插件2022.4.2及之后版本在线地址激活方式已不可用,所以采用本地地址 + 生成的GUID方式 激活 (本文章写的时候,用的JRebel最新版本2023.2.1) 如果需要在线激活 ...
- 「Log」2023.8.22 小记
序幕 早上不到七点到校,6bit 早就到了. 写博客写博客写博客. \(\texttt{8:21}\):把 LCT 的博客写查不多了,SAM 的还是再咕咕咕,先打代码. 学长讲题,LCT 的,讲完吃饭 ...
- LinkedList链表
LinkedList 他是继承的List 双向链表 每当我们new一个linklist对象的时候 LinkedList linkedList = new LinkedList(); 他会先创建一个Li ...
- 鸿蒙运动项目开发:封装超级好用的 RCP 网络库(上)—— 请求参数封装,类型转化器与日志记录篇
鸿蒙核心技术##运动开发## Remote Communication Kit(远场通信服务) 在鸿蒙运动项目开发中,网络通信是不可或缺的一部分.无论是获取运动数据.同步用户信息,还是加载运动视频资源 ...
- 《为什么网站必须部署SSL证书?这几点你一定要知道》
引言:一个真实案例带来的警示 某电商网站运营了两年多,一直没部署SSL证书.直到有一天,用户开始反馈"网站不安全",浏览器直接弹出警告页面,导致访问量骤降,订单几乎归零. 后来他们 ...
- Linux 上安装配置 VNC Server
一:简介 VNC (Virtual Network Console),即 虚拟网络控制台.它是一款优秀的远程控制工具软件,而且是基于 UNIX 和 Linux 操作系统的免费开源的. 二:VNC 服务 ...
- 【闲话 No.1】* 求解??
大概是在中考之前,做过一个奇怪的梦: (梦中)一觉醒来,至公楼前面的空地上突然长出(字面意思)一个非常高级的酒店,huge 突发奇想带着我们去那里全天集训. 每天大概:起床跑去操场进行神秘仪式,然后回 ...
- Spring Boot 集成 tess4j 实现图片识别文本
前言 tesseract是一个开源的光学字符识别(OCR)引擎,它可以将图像中的文字转换为计算机可读的文本.支持多种语言和书面语言,并且可以在命令行中执行.它是一个流行的开源OCR工具,可以在许多不同 ...
- 《Building REST APIs with Flask》读后感
一. 为什么读这本书? 之所以选择这本书其实是因为最近自己在梳理 JWT 的用法.自己曾参与过的一个项目虽然使用的是 Flask 开发,但是授权使用的 PyJWT,当时以为使用 PyJWT 是行业通用 ...