Problem D. What a Beautiful Lake

Description

Weiming Lake, also named "Un-named Lake", is the most famous scenic spot in Peking University. It is located in the north of the campus and is surrounded by walking paths, small gardens, and old red buildings with typical Chinese curly roofs. The lake was once the royal garden in Qing Dynasty. Boya tower stands on a little hill beside the lake. The lake and the tower form a distinctive landscape and a symbol of Peking University.

Weiming Lake is a very good place for studying, reading, skating in the winter, and of course, jogging. More and more students and teachers run or walk around Weiming Lake every day and show how many paces they have covered in the mobile app WeChat Sports to get "Zans" (applauses).

ACMer X also enjoys jogging around Weiming Lake. His watch can measure and record an altitude value every meter. After a round of running, X collected the altitude data around the lake. Now he wants to find out the longest slope around the lake.

Input

There are no more than 20 test cases.

Each case has two lines.

The first line is an integer N (2 <= N <= 100) meaning that the length of the road around the lake is N meters.

The second line contains N integers a1,a2...aN, (0<= a1,a2...aN <= 100) indicating N altitude sample values around the lake. The samples are given in clockwise order, and the distance between two adjacent samples is one meter. Of course the distance between a1 and aN is also one meter.

The input ends by a line of 0.

Output

For each test case, print the length of the longest slope in meters. A slope is a part of the road around the lake, and it must keep going up or going down. If there are no slope, print 0.

Sample Input

4

1 1 1 1

8

5 1 2 3 4 5 6 2

6

5 4 3 2 1 2

10

1 0 2 3 2 2 3 4 3 2

0

Sample Output

0

5

4

4

用dp[i][0   or  1]表示是否比上一个小,或者大的时候,以a[i]为结尾的最大长度。

因为可以循环,所以就直接把数组复制一次在后面,形成2 * n的数组

如果相等就直接跳过好了。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string> int n;
const int maxn = 1e3 + ;
int dp[maxn][];
int a[maxn];
void work() {
for (int i = ; i <= n; ++i) {
cin >> a[i];
}
int t = n;
for (int i = ; i <= n; ++i) {
a[++t] = a[i];
}
memset(dp, , sizeof dp);
for (int i = ; i <= t; ++i) {
if (a[i] == a[i - ]) continue;
if (a[i] > a[i - ]) {
dp[i][] = dp[i - ][] + ;
} else dp[i][] = dp[i - ][] + ;
}
int ans = ;
for (int i = ; i <= t; ++i) {
ans = max(ans, dp[i][]);
ans = max(ans, dp[i][]);
}
cout << ans << endl;
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
IOS;
while (cin >> n && n) work();
return ;
}

Problem D. What a Beautiful Lake dp的更多相关文章

  1. hihocoder 1425What a Beautiful Lake(实验专用)

    Problem D. What a Beautiful Lake Description Weiming Lake, also named "Un-named Lake", is ...

  2. hihoCoder 1425 : What a Beautiful Lake(美丽滴湖)

    hihoCoder #1425 : What a Beautiful Lake(美丽滴湖) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 ...

  3. Problem D: 勤奋的涟漪2 dp + 求导

    http://www.gdutcode.sinaapp.com/problem.php?cid=1049&pid=3 dp[i][state]表示处理了前i个,然后当前状态是state的时候的 ...

  4. Aizu 2305 Beautiful Currency DP

    Beautiful Currency Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest ...

  5. Codeforces Gym 100610 Problem K. Kitchen Robot 状压DP

    Problem K. Kitchen Robot Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10061 ...

  6. Codeforces 713C Sonya and Problem Wihtout a Legend(单调DP)

    [题目链接] http://codeforces.com/problemset/problem/713/C [题目大意] 给出一个数列,请你经过调整使得其成为严格单调递增的数列,调整就是给某些位置加上 ...

  7. (中等) HDU 5293 Tree chain problem,树链剖分+树形DP。

    Problem Description   Coco has a tree, whose vertices are conveniently labeled by 1,2,…,n.There are ...

  8. Codeforces 1085G(1086E) Beautiful Matrix $dp$+树状数组

    题意 定义一个\(n*n\)的矩阵是\(beautiful\)的,需要满足以下三个条件: 1.每一行是一个排列. 2.上下相邻的两个元素的值不同. 再定义两个矩阵的字典序大的矩阵大(从左往右从上到下一 ...

  9. Problem D: 乌龟棋【四维dp】

    Problem D: 乌龟棋 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 24  Solved: 15[Submit][Status][Web Boa ...

随机推荐

  1. HTML5 Canvas 时钟

    1. [图片] QQ截图20120712130049.png ​2. [代码][HTML]代码 <!DOCTYPE html><html lang="en" &g ...

  2. 上传图片 ajax input type="file" 兼容 ie chroem 火狐

    上传图片,转载请注明出处!!! 兼容 ie chroem 火狐 html: <div id="uploadForm"> <input id="file& ...

  3. CentOS6.3安装 Oracle 11g R2

    1.设置系统1.1.包需求 11g很人性化了,增加了检查的机制,还有就是不象10g那样在64位下要安装很多的32位包,只需要安装一个gcc-32bit-4.3就OK了.下列表必须要安装:binutil ...

  4. HDU2203(KMP入门题)

    亲和串 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  5. C/C++获取Linux系统CPU和内存及硬盘使用情况

    需求分析: 不使用Top  df  free 等命令,利用C/C++获取Linux系统CPU和内存及硬盘使用情况 实现: //通过获取/proc/stat (CPU)和/proc/meminfo(内存 ...

  6. saltstack master minion安装配置简单使用

    首先先了解下saltstack是什么,为什么使用它 它与Ansible.Puppet都属于集中管理工具,由于现在企业规模的不断庞大及业务的增长,所需要管理的服务器数量增多,而且大部分机器都属于同类业务 ...

  7. 算法导论17:摊还分析学习笔记(KMP复杂度证明)

    在摊还分析中,通过求数据结构的一系列的操作的平均时间,来评价操作的代价.这样,即使这些操作中的某个单一操作的代价很高,也可以证明平均代价很低.摊还分析不涉及概率,它可以保证最坏情况下每个操作的平均性能 ...

  8. Ladies' Shop

    题意: 有 $n$ 个包,设计最少的物品体积(可重集),使得 1. 对于任意一个总体积不超过给定 $m$ 的物体集合有其体积和 恰好等于一个包的容量. 2.对于每一个包,存在一个物品集合能恰好装满它. ...

  9. python 之队列

    进程和线程模块下都有队列类. 线程队列: # 后进先出->堆栈 q=queue.LifoQueue(3) # 优先级队列,数字越小优先级越高 q=queue.PriorityQueue(3) 进 ...

  10. C# 选择文件路径,选择文件

    // 选择文件: private string SelectPath() { string path = string.Empty; var openFileDialog = new Microsof ...