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. Java生成UUID不重复的id值

    在Java中创建UUID在网上查资料才知道在Java中,变成了UUID.创建方式也出奇简单System.out.println( java.util.UUID.randomUUID());

  2. 网页兼容性测试(工具使用IETESTER、Firefox、360安全浏览器)

    网页兼容性测试主要是针对不同的浏览器进行的测试.由于用户浏览器的不同,往往都会使我们的网页发生页面样式错乱,图片无法显示等问题.对于前端开发工程师来说,确保代码在各种主流浏览器的各个版本中都能正常显示 ...

  3. codeforces 463C. Gargari and Bishops 解题报告

    题目链接:http://codeforces.com/contest/463/problem/C 题目意思:要在一个 n * n 大小的棋盘上放置两个bishop,bishop可以攻击的所有位置是包括 ...

  4. ubuntu nginx 安装 certbot(letsencrypt)

    https://certbot.eff.org 到上面网站按照步骤安装certbot, 安装完成后,certbot 生成证书有两种方式 第一种:standalone模式,certbot 会启动自带的n ...

  5. DGA域名——可以每天只生成一个域名,因此最多存在365个 DGA域名;

    Mirai变种中的DGA 分享到: 发布时间:2016-12-12 16:02:57 作者:360网络安全研究院 投稿方式:发送邮件至linwei#360.cn,或登陆网页版在线投稿 那个导致美国断网 ...

  6. mongodb压缩——snappy、zlib块压缩,btree索引前缀压缩

    MongoDB 3.0 WiredTiger Compression and Performance One of the most exciting developments over the li ...

  7. VC6.0 快捷键

    F1: 帮助 Ctrl+O   :OpenCtrl+P   :PrintCtrl+N   :NewCtrl+Shift+F2 :清除所有书签F2    :上一个书签Shift+F2 :上一个书签Alt ...

  8. 日志的打印 —— Java 支持

    1. java.util.logging.Logger 日志级别(logLevel) OFF,Integer.MAX_VALUE SEVERE,1000 WARNING,900 INFO,800 CO ...

  9. cygwin Could not create directory '/home/Administrator/.ssh'

    在cygwin下运行: ssh-keygen -C "634772208@qq.com" -t rsa 时,出现如下错误: cygwin Could not create dire ...

  10. bzoj3680

    $模拟退火$ $这种全局最优的问题用模拟退火$ $模拟退火就是每次向四周随机移动,移动的幅度和温度成正比,如果新的位置更优就接受,否则按一定概率接收,概率和温度成正比$ $最后稳定后再在最优解附近蹦跶 ...