• ZOJ4024 Peak


     题意 给出一个数组 判断这个数组是否形成了一个“山峰” 即中间有个数最大 从第一个数到这个数递增 从这个数到最后一个数递减

    模拟 从两端分别以递增和递减判断 看第一个不满足递增或递减的数是否相等并且没越界就可以了

    AC代码:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 typedef unsigned long long ull;
     5 
     6 namespace io {
     7     const int SIZE = 1e7 + 10;
     8     char inbuff[SIZE];
     9     char *l, *r;
    10     inline void init() {
    11         l = inbuff;
    12         r = inbuff + fread(inbuff, 1, SIZE, stdin);
    13     }
    14     inline char gc() {
    15         if (l == r) init();
    16         return (l != r) ? *(l++) : EOF;
    17     }
    18     void read(int &x) {
    19         x = 0; char ch = gc();
    20         while(!isdigit(ch)) ch = gc();
    21         while(isdigit(ch)) x = x * 10 + ch - '0', ch = gc();
    22     }
    23 } using io::read;
    24 
    25 int main(){
    26     int t;
    27     scanf("%d", &t);
    28     int n;
    29     int a[100005];
    30     while (t--){
    31         memset(a, 0, sizeof(a));
    32         scanf("%d", &n);
    33         for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    34         int l = 1, r = n;
    35         while (l < n && a[l] < a[l + 1]) l++;
    36         while (r > 1 && a[r] < a[r - 1]) r--;
    37         if (l == r && l != 1 && l != n) cout<<"Yes"<<endl;
    38         else cout<<"No"<<endl;
    39     }
    40     return 0;
    41 }
  • 相关阅读:
    HDU 1058 Humble Numbers
    HDU 1421 搬寝室
    HDU 1176 免费馅饼
    七种排序算法的实现和总结
    算法纲要
    UVa401 回文词
    UVa 10361 Automatic Poetry
    UVa 537 Artificial Intelligence?
    UVa 409 Excuses, Excuses!
    UVa 10878 Decode the tape
  • 原文地址:https://www.cnblogs.com/Misuchii/p/10969647.html
Copyright © 2020-2023  润新知