zoukankan      html  css  js  c++  java
  • POJ 3298 Antimonotonicity (思维)

    题目链接:http://poj.org/problem?id=3298

    找一个最长不要求连续的子序列,如a1 > a3 < a6 > a7 ...

    举个例子模拟一下差不多明白了,a[i - 1]与a[i]有依赖关系。

     1 //#pragma comment(linker, "/STACK:102400000, 102400000")
     2 #include <algorithm>
     3 #include <iostream>
     4 #include <cstdlib>
     5 #include <cstring>
     6 #include <cstdio>
     7 #include <vector>
     8 #include <cmath>
     9 #include <ctime>
    10 #include <list>
    11 #include <set>
    12 #include <map>
    13 using namespace std;
    14 typedef long long LL;
    15 typedef pair <int, int> P;
    16 const int N = 1e5 + 5;
    17 int a[N];
    18 
    19 int main()
    20 {
    21     int t, n;
    22     scanf("%d", &t);
    23     while(t--) {
    24         scanf("%d", &n);
    25         for(int i = 1; i <= n; ++i) {
    26             scanf("%d", a + i);
    27         }
    28         int Max = 1, num = a[1];
    29         for(int i = 2; i <= n; ++i) {
    30             if(Max % 2 && a[i] < num) {
    31                 Max++;
    32             } else if(Max % 2 == 0 && a[i] > num) {
    33                 Max++;
    34             }
    35             num = a[i];
    36         }
    37         printf("%d
    ", Max);
    38     }
    39     return 0;
    40 }
  • 相关阅读:
    链表的常用操作
    android简易论坛的制作
    Bmob后端云的使用
    马哥第九周
    马哥第八周
    马哥第七周
    马哥第六周
    马哥第五周
    马哥第四周
    马哥第三周
  • 原文地址:https://www.cnblogs.com/Recoder/p/5821610.html
Copyright © 2011-2022 走看看