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

时间限制:1000ms
单点时限:1000ms
内存限制:256MB

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.

    未名湖,也叫”无名湖”,是北大的著名景观。未名湖位于校园北部,四周环有步行道、小花园,红色的中式经典卷棚顶老建筑。此湖曾为清朝御花园。博雅塔伫立在湖边小山上。这一湖一塔即是北大独特的标志景观。
未名湖是读书学习,冬日滑冰,以及慢跑的好去处。越来越多的师生每天绕湖或行或走,并且在手机应用微信运动上展示步数求”赞”(鼓掌)。
ACMer X 也入坑未名湖环跑。他的手表可以测量和记录单位为米的高度。跑了一圈后,X收集了湖周围的高度数据。现在他想找出湖周围最长的斜坡。

CN

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.

    测试用例不超过20组。
每个用例只有两行。
第一行为一个整数N ( <= N <= ) 表示环湖道路的长度为N米。
第二行有N个整数a1, a2 ... aN, ( <= a1, a2 ... aN <= ) 表示N个环绕湖的样本高度。样本按逆时针排序,两个样本间的距离为一米。当然了,a1 与 aN的间距也是一米。

CN

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.

    对于每个测试用例,输出最长斜坡的长度为多米。斜坡是环湖道路的一部分,必须保持上升或下降。如果没有斜坡,则输出0。

CN

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

题解

  水题,走两遍就能求出结果了。
  注意题目意思的要求是斜坡为严格递增或递增,有相等的两个数即会断开斜坡的计算。

代码 C++

 #include<cstdio>
#include <cstring>
#include <algorithm>
int main(){
int n, i, tmp1, tmp2, data[], opt;
while (scanf("%d", &n), n){
for (i = ; i < n; ++i) scanf("%d", data + i);
memcpy(&data[i], data, sizeof(int)*n);
n <<= ; tmp1 = tmp2 = opt = ;
for (i = ; i < n; ++i){
if (data[i] > data[i - ]) opt = std::max(++tmp1, opt);
else tmp1 = ;
if (data[i] < data[i - ]) opt = std::max(++tmp2, opt);
else tmp2 = ; }
printf("%d\n", opt); }
return ; }

最新文章

  1. 关于MyCAT字符集的验证
  2. python面向对象进阶(八)
  3. iOS 9的升级后的问题处理
  4. 【freemaker】之自定义指令&lt;#macro&gt;
  5. 利用HttpWebRequest访问WebApi
  6. iOS进阶学习-CoreData
  7. zookeeper使用场景【转】
  8. jquery 中 form的使用
  9. C语言初学 简单计算器计算加减乘除程序
  10. sublime 前端开发工具
  11. 神奇的i=i++
  12. IOS开发应用
  13. 使用BeautifulSoup和正则表达式爬取时光网不同地区top100电影并使用Matplotlib对比
  14. Java接口实现传参
  15. 动态规划——Burst Ballons
  16. Vue系列之 =&gt; webpack处理样式文件
  17. 转://通过udev创建ASM共享磁盘(RAC)
  18. pyqt5-对文本样式进行操作
  19. phpmyadmin登录提示2005错误
  20. 使用linux下的C操作SQLLITE

热门文章

  1. 关于dll的一点收获
  2. MVC之权限管理-网站开发之路
  3. Unity: Invalid serialized file version xxx Expected version: 5.3.4f1. Actual version: 5.3.5f1.
  4. hdu5722 Jewelry
  5. 验证控件,解决用于ajax提交前的验证,不是submit提交的验证
  6. Web 播放声音 — Flash 篇 (播放 AMR、WAV)
  7. python学习笔记系列----(四)模块
  8. Git远程操作详解
  9. vue.js 渲染完成回调
  10. windows2008 c盘清理