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\n", Max);
38     }
39     return 0;
40 }

 

转载于:https://www.cnblogs.com/Recoder/p/5821610.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值