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 (2 <= N <= 100) 表示环湖道路的长度为N米。第二行有N个整数a1, a2 ... aN, (0 <= a1, a2 ... aN <= 100) 表示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++

 1 #include<cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 int main(){
 5     int n, i, tmp1, tmp2, data[205], opt;
 6     while (scanf("%d", &n), n){
 7         for (i = 0; i < n; ++i) scanf("%d", data + i);
 8         memcpy(&data[i], data, sizeof(int)*n);
 9         n <<= 1; tmp1 = tmp2 = opt = 0;
10         for (i = 1; i < n; ++i){
11             if (data[i] > data[i - 1]) opt = std::max(++tmp1, opt);
12             else tmp1 = 0;
13             if (data[i] < data[i - 1]) opt = std::max(++tmp2, opt);
14             else tmp2 = 0;
15
16         }
17         printf("%d\n", opt);
18
19     }
20     return 0;
21
22 }

转载于:https://www.cnblogs.com/Simon-X/p/6081970.html

hihoCoder 1425 : What a Beautiful Lake(美丽滴湖)相关推荐

  1. 小王梦游记五---最美丽的湖

    小王梦游记五-最美丽的湖 序章 入选 王爷是一个富可敌国的大老板,那天在街上偶遇,他心情好,让我坐上他的船玩玩,然后我就上去,这条船很奇怪,明明看上去只是一叶扁舟,但是试图划船时却感觉使不上力,只能让 ...

  2. 基于Delta Lake构建数据湖仓体系

    直播回放地址:https://developer.aliyun.com/live/249789 导读: 今天很高兴能与大家分享如何通过 Delta Lake 构建湖仓架构. 全文将围绕以下四个部分展开 ...

  3. Wow Beautiful JEJU -美丽的济州

    岛海相映,海天相依的济州岛-韩国第一大岛屿, 韩国第一大旅游胜地!  这里就是富有幻想魅力的济州岛-春夏秋冬一年四季分明,各具特色.自然神秘幻想的济州岛,被称为亚洲夏威夷现在就让我们一同前去感受一下济 ...

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

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

  5. 确保河道环境_扮靓美丽河湖 | 河道保洁“神器”, 上线!

    为加强河道巡回保洁力度改善河道水质环境梁溪多款河道保洁"神器"已正式上线 这些水上"神器"大大提高了 梁溪"碧水保卫战"的进程赶快跟着小布一 ...

  6. 汤和油谁的沸点高_使用美丽的汤和python中的请求进行网络抓取

    汤和油谁的沸点高 What is Web Scraping? 什么是网页抓取? Web Scraping is a technique employed to extract large amount ...

  7. 【详谈 Delta Lake 】系列技术专题 之 Streaming(流式计算)

    简介: 本文翻译自大数据技术公司 Databricks 针对数据湖 Delta Lake 的系列技术文章.众所周知,Databricks 主导着开源大数据社区 Apache Spark.Delta L ...

  8. 【详谈 Delta Lake 】系列技术专题 之 湖仓一体( Lakehouse )

    简介: 本文翻译自大数据技术公司 Databricks 针对数据湖 Delta Lake 的系列技术文章.众所周知,Databricks 主导着开源大数据社区 Apache Spark.Delta L ...

  9. 【详谈 Delta Lake 】系列技术专题 之 特性(Features)

    简介: 本文翻译自大数据技术公司 Databricks 针对数据湖 Delta Lake 的系列技术文章.众所周知,Databricks 主导着开源大数据社区 Apache Spark.Delta L ...

  10. 数据湖(Data Lake)-剑指下一代数据仓库

    数据湖是数据仓库的补充,是为了解决数据仓库漫长的开发周期,高昂的开发.维护成本,细节数据丢失等问题出现的. 数据湖大多是相对于传统基于RDBMS的数据仓库,而从2011年前后,也就是数据湖概念出现的时 ...

最新文章

  1. HTML+JS弹出可移动DIV遮罩层
  2. JDBC驱动程序的四种方式
  3. omnet++ : could not be resolved 或error: coreexception 的解决
  4. linux如何查tomcat是否安装,如何检测linux机器上是否安装了tomcat和ant
  5. selenium操作chrome时的一些配置
  6. 世界杯快到了,看我用Python爬虫实现(伪)球迷速成!
  7. 程序员的噩梦,你遇到过哪几条?
  8. 将速度加快到自己的个人代码生成器中
  9. 计算机网络,IP地址概念及IP地址详细分类介绍、及子网掩码详细介绍MAC地址介绍、网络位,主机位、网络地址、广播地址。
  10. 计算机专业盲打,在win7系统电脑练习盲打的方法
  11. 精功科技押宝互联网服务业 盘古数据承诺未来业绩大逆转
  12. 小心那些年末还在努力的狠人!
  13. 多线程断点下载开发总结(一) - Http head Range标记
  14. 左程云算法笔记(未完待续)
  15. 基于Android技术的物联网应用开发
  16. 我们的地盘,我们做主
  17. NLP入门学习3——句法分析(基于LTP4)
  18. 普通运维人员真的就是秋后的蚂蚱吗?
  19. 计算机音乐天使重构,天使重构
  20. 欠缺的_习惯累积沉淀_新浪博客

热门文章

  1. Django web开发(一) - 前端
  2. 钉钉企业内微应用对现有系统的免登和消息发送
  3. matlab 使用c2d的离散化笔记
  4. 从全球制造业的迁移史,看中国制造业未来会怎么走?
  5. 旅游|受不住热暑的炎烤 就到山上“凉拌”空气去
  6. 【最短路】白银莲花池
  7. 金三银四,给大家肝一下面试题~
  8. MATLAB——LTI Viewer
  9. 论文笔记-Monocular Depth Estimation as Regression of Classification using Piled Residual Networks
  10. 怎么将多张图片打印在一张A4纸上?