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 ; }

hihoCoder 1425 : What a Beautiful Lake(美丽滴湖)的更多相关文章

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

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

  2. Problem D. What a Beautiful Lake dp

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

  3. 893B. Beautiful Divisors#美丽的因子(打表法)

    题目出处:http://codeforces.com/problemset/problem/893/B 题目大意:找到一个数在二进制下,最大的以k个连续的1和k-1个连续的0组成的数字作为因子 #in ...

  4. English trip V1 - B 14. There Are Flowers in My Office 我办公室里有花 Teacher:Lamb Key: There be(is/are)

    In this lesson you will learn to describe a room or place. 这节课讲学习描述一个房间或地方 课上内容(Lesson) 1. Where do ...

  5. English trip V1 - 24. Accommodations Teacher:Maple Key: make suggestions 提出建议

    In this lesson you will learn to make suggestions. 在本课程中,您将学习如何提出建议. 课上内容(Lesson) Which place  would ...

  6. The 2016 ACMICPC Asia Beijing Regional Contest

    A. Harmonic Matrix Counter (3/19) B. Binary Tree (1/14) C. Asa's Chess Problem (21/65) [ Problem ] 给 ...

  7. Build2016上值得一看的大数据相关Session

    (此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:Build2016开完很久了,现在才来回顾下,就说说那些和大数据相关的Session, ...

  8. in on at 总结

    in,on,at的时间用法和地点用法 一.in, on, at的时间用法 ①固定短语: in the morning/afternoon/evening在早晨/下午/傍晚, at noon/night ...

  9. Daily record-November

    November 11. I managed to grab her hand. 我抓到了她的手.2. He passed a hand wearily over his eyes. 他疲倦地用手抹了 ...

随机推荐

  1. asp.net中http提交数据所遇到的那些坑

    http提交数据有两种形式,get和post,不知道的同学请联系度娘. 1.aspnet:MaxHttpCollectionKeys 业务场景:业务很简单,手机端读取本地通讯录,将所有通讯录提交到后台 ...

  2. FORM中需要反复选择LOV

    注意:1.字段长度问题 2.提示显示样式:第一条记录 3.那些不现实的返回项,或者是只读的返回项可以  将从列表中验证 改为 否    比如一个LOV 返回2个值 但是其实只用选择前一个就可以带出后一 ...

  3. mono支持gb2312

    需要安装mono-locale-extras 输入命令 yum install -y mono-locale-extras 安装即可

  4. String相关的问题

    基本事实:对于字符串常量,如果内容相同,Java认为它们代表同一个String对象.而用关键字new 调用的构造器,总是会创建新的对象,无论内容是否相同.字符串常量是放在常量池(或者叫常量缓冲区)里面 ...

  5. Qt之布局管理--基本布局

    Qt提供的布局类以及他们之间的继承关系QLayout-----QGirdLayout | ---QBoxLayout----QHBoxLayout | --QVBoxLayout----------- ...

  6. linux 使用/proc文件系统 实现用户空间与内核模块之间通信

    项目中可能会用到用户态和内核模块之间进行通信的功能.想到linux系统本身很多通信都是通过/proc文件系统来的,比如修改网络中连接跟踪表连接数限制/proc/sys/net/netfilter/nf ...

  7. JAVA中的异常及处理异常的方法

    异常 这是我老师的喜好:就是说一上来就拿一张图给大家看看,过过瘾-_- 这是一张: 异常分类图 来,这里还有一张带中文的常见异常截图!!! 1:先来说说什么是异常吧: 其实就是"阻止当前方法 ...

  8. robots.txt文件没错,为何总提示封禁

    大家好,我的robots.txt文件没错,为何百度总提示封禁,哪位高人帮我看看原因,在此谢过. 我的站点www.haokda.com,robots.txt如下: ## robots.txt for P ...

  9. 108 vpn iptables

    [root@fge108 webapps]# iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -j SNAT --to-source 47.88.1 ...

  10. js,jquery获取浏览器信息

    1.js获取: 查看:window.navigator 2.jQuery获取: chrome firefox 推荐使用navigator获取userAgent然后去正则匹配 参考匹配规则:http:/ ...