The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple -A Peak
Peak
Time Limit: 1 Second Memory Limit: 65536 KB
A sequence of integers is called a peak, if and only if there exists exactly one integer such that , and for all , and for all .
Given an integer sequence, please tell us if it's a peak or not.
Input
There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:
The first line contains an integer (), indicating the length of the sequence.
The second line contains integers (), indicating the integer sequence.
It's guaranteed that the sum of in all test cases won't exceed .
Output
For each test case output one line. If the given integer sequence is a peak, output "Yes" (without quotes), otherwise output "No" (without quotes).
Sample Input
7
5
1 5 7 3 2
5
1 2 1 2 1
4
1 2 3 4
4
4 3 2 1
3
1 2 1
3
2 1 2
5
1 2 3 1 2
Sample Output
Yes
No
No
No
Yes
No
No
原题网站:
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5752 题意:给你一个数组让你求这个数组是不是一个山峰数组,就这个数组有先单调递增之后再单调递减两种情况 分别用flag1,flag2来标记是否有单调递增和单调递减情况,并且判断在递减情况是否有递增情况,但是要注意如果有相同的情况是不满足递增和递减要直接输出No(这里wa一次) 代码:
#include<bits/stdc++.h>
using namespace std; int a[];
int main()
{
std::ios::sync_with_stdio(false);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
for(int i=;i<n;i++){
cin>>a[i];
}
int flag=;
int flag1=,flag2=,flag4=;
int flag3=;
for(int i=;i<n;i++){
if(a[i]==a[i-]){//判断是否有相同的值的情况
flag4=;
}
if(!flag){//标记是否有单调递增
if(a[i]>a[i-]){
flag1=;
}
if(a[i]<a[i-]){//标记是否单调递减
flag=;
flag2=;
}
}
else{//标记是否在单调递减的时候还有单调递增的情况
if(a[i]>a[i-]){
flag3=;
break;
}
}
}
if(flag3==||(flag1+flag2!=)||flag4==)cout<<"No"<<endl;
else cout<<"Yes"<<endl;
}
return ;
}
The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple -A Peak的更多相关文章
- The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - L Doki Doki Literature Club
Doki Doki Literature Club Time Limit: 1 Second Memory Limit: 65536 KB Doki Doki Literature Club ...
- 2018浙江省赛(ACM) The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple
我是铁牌选手 这次比赛非常得爆炸,可以说体验极差,是这辈子自己最脑残的事情之一. 天时,地利,人和一样没有,而且自己早早地就想好了甩锅的套路. 按理说不开K就不会这么惨了啊,而且自己也是毒,不知道段错 ...
- The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - M Lucky 7
Lucky 7 Time Limit: 1 Second Memory Limit: 65536 KB BaoBao has just found a positive integer se ...
- The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - J CONTINUE...?
CONTINUE...? Time Limit: 1 Second Memory Limit: 65536 KB Special Judge DreamGrid has clas ...
- The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - B King of Karaoke
King of Karaoke Time Limit: 1 Second Memory Limit: 65536 KB It's Karaoke time! DreamGrid is per ...
- ZOJ 4033 CONTINUE...?(The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple)
#include <iostream> #include <algorithm> using namespace std; ; int a[maxn]; int main(){ ...
- The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - F 贪心+二分
Heap Partition Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge A sequence S = { ...
- The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - C 暴力 STL
What Kind of Friends Are You? Time Limit: 1 Second Memory Limit: 65536 KB Japari Park is a larg ...
- ZOJ 3962 E.Seven Segment Display / The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple E.数位dp
Seven Segment Display Time Limit: 1 Second Memory Limit: 65536 KB A seven segment display, or s ...
随机推荐
- P2874 [USACO07FEB]新牛棚Building A New Barn
题目描述 After scrimping and saving for years, Farmer John has decided to build a new barn. He wants the ...
- DataBase -- JOIN
SQL JOIN:用于根据两个或多个表中列的关系,从这些表中查数据. (为了得到完整数据,我们需要从两个或多个表中获取结果.) 例如W3School中列出的实例,使用如下语句: select Pers ...
- POJ2289:Jamie's Contact Groups(二分+二分图多重匹配)
Jamie's Contact Groups Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/ ...
- js用for of 遍历数组
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Javascript 的addEventListener()及attachEvent()区别分析
大家都知道事件的用法就是当某个事件(状况)被触发了之后就会去执行某个Function, 尤其是Javascript, 在当红AJAX的催化下, 了解Javascript的Event用法更加重要, 在这 ...
- MFC 监控界面上所有文本框值的变化
//控件消息,菜单,按钮等 BOOL CXXDlg::OnCommand(WPARAM wParam, LPARAM lParam) { // TODO: 在此添加专用代码和/或调用基类 int wm ...
- vue入门知识
vue的特点在于:响应的数据绑定.组合的视图组件. vue的文件,分成三个部分<template>html模板</template> <script>js< ...
- MyBatis对象关联关系----多对多的保存与查询
模拟情景: 对象:学生,课程 关系:一个学生可选多个课程,一门课程可被多个学生选择 一.保存 1.创建数据库表,student,course,student_course,其中student_cour ...
- Spring - IoC(5): 集合属性的注入
如果 Bean 的属性是个集合,则可以使用 <list/>.<set/>.<map/> 和 <props/> 元素向 List.Set.Map 和 Pr ...
- 【BZOJ2440】完全平方数 [莫比乌斯函数]
完全平方数 Time Limit: 10 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description 小X自幼就很喜欢数. 但奇怪的是 ...