nyoj 370-波动序列
来源:互联网 发布:看成绩的软件 编辑:程序博客网 时间:2024/04/30 09:14
http://acm.nyist.net/JudgeOnline/problem.php?pid=370
波动序列
时间限制:1000 ms | 内存限制:65535 KB
难度:2
- 描述
有一个长度为N的整数序列,序列里面的数是两两不同的,现在要在里面找一个波动序列,这个序列越长越好。
比如有波动序列{a0,a1,a2…an-1},则a0 > a1 < a2 > a3 < …
- 输入
- 第一行输入一个数T,代表有T个任务,T不大于50。
对于每个任务,输入格式为
N a0 a1 a2 … aN-1
其中N<=30000,测试数据保证序列的数两两不同。 - 输出
- 对于每个任务,输出最长的波动序列长度
- 样例输入
45 1 2 3 4 55 5 4 3 2 15 5 1 4 2 35 2 4 1 3 5
- 样例输出
1253
#include<iostream>using namespace std;const int MAX = 30000 + 10;int a[MAX];int main() { int T; cin >> T; while (T--) { int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int b = a[0], len = 1; int f = 1; //f=1表示递增 for (int i = 1; i < n; i++) { if (f && b > a[i]) { f = 0; len++; } else if (!f && b < a[i]) { f = 1; len++; } b = a[i]; } cout << len << endl; }}
0 0
- NYOJ 370 波动序列
- nyoj 370-波动序列
- NYOJ 370 波动序列
- NYOJ 370 波动序列
- NYOJ 370 波动序列 dp 动态规划
- NYOj题目370波动序列(dp)
- NYOJ 370 波动序列 (有意思的题)
- 波动序列
- 波动序列
- 波动序列
- 波动序列解题报告
- 最长波动序列【模拟】
- NYOJ370-波动序列
- 洛谷P3929波动序列
- Tyvj 1521 最长波动序列
- 求解最长的波动序列
- hrbust 1131 波动序列【水题】
- 【NOIP2013花匠】(最长波动序列)
- 介绍Robotium+Orange实现androidUI自动化测试
- UIApplicationMain函数概述
- linux网络编程--Circular Buffer(Ring Buffer) 环形缓冲区的设计与实现
- uva 540 - Team Queue
- Linux 打开文件数1024限制的原理以及解决办法
- nyoj 370-波动序列
- 全局变量、局部变量、静态全局变量、静态局部变量的区别
- 那些年的setter与getter与反射
- 【工具类】ViewHolder模式超简洁写法
- Android 错误情形列表
- 简明解释算法中的大O符号
- poj3275
- C函数-字符串转换篇 atof/atoi/atol/gcvt/strod/strol/strtoul/toascii/tolower/toupper
- Android当中Configuration类简介