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

  1. 7
  2. 5
  3. 1 5 7 3 2
  4. 5
  5. 1 2 1 2 1
  6. 4
  7. 1 2 3 4
  8. 4
  9. 4 3 2 1
  10. 3
  11. 1 2 1
  12. 3
  13. 2 1 2
  14. 5
  15. 1 2 3 1 2

Sample Output

  1. Yes
  2. No
  3. No
  4. No
  5. Yes
  6. No
  7. No
    原题网站:
    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5752
  8.  
  9. 题意:给你一个数组让你求这个数组是不是一个山峰数组,就这个数组有先单调递增之后再单调递减两种情况
  10.  
  11. 分别用flag1flag2来标记是否有单调递增和单调递减情况,并且判断在递减情况是否有递增情况,但是要注意如果有相同的情况是不满足递增和递减要直接输出No(这里wa一次)
  12.  
  13. 代码:
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int a[];
  5. int main()
  6. {
  7. std::ios::sync_with_stdio(false);
  8. int t;
  9. cin>>t;
  10. while(t--){
  11. int n;
  12. cin>>n;
  13. for(int i=;i<n;i++){
  14. cin>>a[i];
  15. }
  16. int flag=;
  17. int flag1=,flag2=,flag4=;
  18. int flag3=;
  19. for(int i=;i<n;i++){
  20. if(a[i]==a[i-]){//判断是否有相同的值的情况
  21. flag4=;
  22. }
  23. if(!flag){//标记是否有单调递增
  24. if(a[i]>a[i-]){
  25. flag1=;
  26. }
  27. if(a[i]<a[i-]){//标记是否单调递减
  28. flag=;
  29. flag2=;
  30. }
  31. }
  32. else{//标记是否在单调递减的时候还有单调递增的情况
  33. if(a[i]>a[i-]){
  34. flag3=;
  35. break;
  36. }
  37. }
  38. }
  39. if(flag3==||(flag1+flag2!=)||flag4==)cout<<"No"<<endl;
  40. else cout<<"Yes"<<endl;
  41. }
  42. return ;
  43. }
  1.  
  1.  

The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple -A Peak的更多相关文章

  1. 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 ...

  2. 2018浙江省赛(ACM) The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple

    我是铁牌选手 这次比赛非常得爆炸,可以说体验极差,是这辈子自己最脑残的事情之一. 天时,地利,人和一样没有,而且自己早早地就想好了甩锅的套路. 按理说不开K就不会这么惨了啊,而且自己也是毒,不知道段错 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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(){ ...

  7. 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 = { ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. BZOJ3243 [Noi2013]向量内积 【乱搞】

    题目链接 BZOJ3243 题解 模数只有\(2\)或\(3\),可以大力讨论 如果模数为\(2\),乘积结果只有\(1\)或\(0\) 如果一个向量和前面所有向量乘积都为\(1\),那么其和前面向量 ...

  2. vector创建2维数组

    以前我要建立一个二维数组,总是使用 int N=5, M=6; vector<vector<int> > Matrix(N); for(int i =0; i< Matr ...

  3. 如何把阿里云的服务器配置为mac的共享文件夹(亲测有效)

    写在开头的就是,我只能百分之九十确定这个是真的有效....毕竟试了太多的方法,最后莫名其妙的就好了.. - -# 基础的步骤就不说了,网上一搜一大把,大家可能follow了所有的步骤以后发现还是连接不 ...

  4. JavaScript中Array(数组)的属性和方法(转)

    数组有四种定义的方式 使用构造函数:var a = new Array();var b = new Array(8);var c = new Array("first", &quo ...

  5. 调整文本输入框placeholder的颜色等样式

    input::-webkit-input-placeholder{     color: white !important;}input:-moz-placeholder{    color: whi ...

  6. Python基础(4)_集合、布尔类型

    一.集合 集合的作用一:关系运算集合的作用二:去重 定义集合:集合内的元素必须是唯一的:集合内的元素必须是可hash的,也是就不可变类型:集合是无序的 s={'egon',123,'egon','1' ...

  7. TCP(二)

    TCP半连接和全连接问题 TCP握手过程详解 如上图所示,关键部分:syns queue(半连接队列)和accept queue(全连接队列) 正常情况下的处理过程如下: 1)当server端收到cl ...

  8. [POJ2135]最小费用最大流

    一直由于某些原因耽搁着...最小费用最大流没有搞会. 今天趁着个人状态正佳,赶紧去看看,果然30min不到看会了算法+模板并且A掉了一道题. 感觉最小费用最大流在学过了最大流之后还是挺好理解的.找到从 ...

  9. bzoj 2151 贪心

    几乎完全类似于1150的思路,直接参考那个就行了. http://www.cnblogs.com/BLADEVIL/p/3527193.html /************************** ...

  10. 阻塞DOM

    DOM是解析后的HTML. 这些阻塞因素我们可以叫做 阻塞渲染的资源 ,例如 HTML.CSS(也包括web font)和 JavaScript. 请注意,图像是不会阻塞渲染的 ,所以如果有图像落在蓝 ...