博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
洛谷P1317 低洼地
阅读量:4352 次
发布时间:2019-06-07

本文共 1108 字,大约阅读时间需要 3 分钟。

题目描述

一组数,分别表示地平线的高度变化。高度值为整数,相邻高度用直线连接。找出并统计有多少个可能积水的低洼地?

如图:地高变化为 0 1 0 2 1 2 0 0 2 0

输入输出格式

输入格式:

 

两行,第一行n,表示有n个数。第2行连续n个数表示地平线高度变化的数据,保证首尾为0。(3<=n<=10000,0<=高度<=1000)

 

输出格式:

 

一个数,可能积水低洼地的数目。

 

输入输出样例

输入样例#1: 
100 1 0 2 1 2 0 0 2 0
输出样例#1: 
3 数组模拟lyq大坑比
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #define LL long long 8 #define lb(x) ((x)&(-x)) 9 using namespace std;10 const int MAXN=1000001;11 inline int read()12 {13 char c=getchar();int x=0,f=1;14 while(c<'0'||c>'9') { if(c=='-') f=-1;c=getchar();}15 while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();return x*f;16 }17 int n;18 int a[MAXN];19 int main()20 {21 n=read();22 for(int i=1;i<=n;i++)23 a[i]=read();24 int nowhigh=a[2],ans=0;25 for(int i=2;i<=n;i++)26 {27 if(a[i]>nowhigh) nowhigh=a[i];28 if(a[i+1]
a[i+1]) ans++,nowhigh=a[i+2],i=i+1;29 }30 printf("%d",ans);31 return 0;32 }33 34 /*35 1136 37 10 9 8 8 8 7 8 2 1 1 238 */

 

 

转载于:https://www.cnblogs.com/zwfymqz/p/7711908.html

你可能感兴趣的文章
NIO(2):Channel
查看>>
Consistent Hashing算法
查看>>
C++基础--完善Socket C/S ,实现客户端,服务器端断开重连
查看>>
lvs,nginx反向代理,虚拟主机
查看>>
jquip,更简洁的代码
查看>>
【OJ】PAT-A解题报告
查看>>
文档语法
查看>>
利用套接字实现进程通信一例
查看>>
linux中shell变量$#,$@,$0,$1,$2的含义解释
查看>>
常用的shell命令整理
查看>>
A Brief Introduction to the Design of UBIFS
查看>>
了解你的Linux系统:必须掌握的20个命令
查看>>
js setInterval 启用&停止
查看>>
knockoutJS学习笔记04:监控属性
查看>>
Linux下启动/关闭Oracle
查看>>
session和cookie的区别
查看>>
oracle 数据库、实例、服务名、SID
查看>>
web.xml文件的作用
查看>>
linux下oracle调试小知识
查看>>
alert弹出窗口,点击确认后关闭页面
查看>>