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. Keras 可视化 model

    参考:https://keras.io/visualization/ error解决参考:http://blog.csdn.net/wangjian1204/article/details/50346 ...

  2. 中缀表达式std

    #include<cstdio>#include<cstdlib>#include<string>#include<cstring>using name ...

  3. AutoIt with XML: Add a child/grandchild node or remove any node

    Sometimes, we have to use AutoIt script to edit an xml, add a node or remove a node, to make some de ...

  4. 洛谷P1522牛的旅行——floyd

    题目:https://www.luogu.org/problemnew/show/P1522 懒于仔细分情况而直接像题解那样写floyd然后不明白最后一步max的含义了... 分开考虑怎么保证在一个内 ...

  5. 增加,删除GMS包

    1. device/hiteq/vtab_1050_standard/httek.mk BUILD_GMS:=yes GMS_VARIANT:=mini 2. rm out/target/produc ...

  6. glance image-create

    glance image-create

  7. windows安装PHP5.4+Apache2.4+Mysql5.5

    windows安装PHP5.4+Apache2.4+Mysql5.5 作者:星之宇 ┊ 时间:2012-10-18 14:27 ┊ 分类: 网站技术 ┊ 阅读:1232 ┊ 评论:16 最近听说PHP ...

  8. P2P通讯初步实现

    原文URL: http://www.cnblogs.com/dlwang2002/archive/2008/09/16/1291793.html 1:基于Socket连接: 2:在四个局域网内测试通过 ...

  9. Visual Studio 2017 本地调试 Chrome浏览器自动退出

    在使用VS 2017(15..6 .15.7)对.NET Core MVC应用程序进行本地调试的时候,选择使用Chrome浏览器.但输入中文 就自动关闭Chrome浏览器,随后结束调试.但复制.粘贴中 ...

  10. cf 424

    Office Keys 首先显然有随人位置的递增,钥匙的位置也要递增,这样考虑两张做法: 1.$f(i,j)$ 表示前i个人,钥匙到第j个最少用的最大时间,然后$O(nK)$ dp 2.二分时间,对于 ...