T1

Problem

洛谷

Solution

这是线性扫描题吧。

就从1 ~ n 循环,若比起面高,则 ans += h[i] - h[i - 1]。

Code

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
ll read()
{
ll x = 0; int zf = 1; char ch;
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return x * zf;
}
int x[100005]; int main()
{
int n = read();
x[0] = 0;
int ans = 0;
for (int i = 1; i <= n; i++)
{
x[i] = read();
if (x[i] > x[i - 1]) ans += x[i] - x[i - 1];
}
printf("%d\n", ans);
}

T2

Problem

洛谷

Solution

其实就是求一个数列里拐点数+1,然后O(n)扫一遍就好了。

Code

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
ll read()
{
ll x = 0; int zf = 1; char ch;
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return x * zf;
}
int x[100005]; int main()
{
int n = read();
x[1] = read();
int ansx = 1, ansy = 1;
for (int i = 2; i <= n; i++)
{
x[i] = read();
if (x[i] == x[i - 1]) continue;
if (x[i] > x[i - 1]) ansx = max(ansx, ansy + 1);
else ansy = max(ansy, ansx + 1);
}
printf("%d\n", max(ansx, ansy));
}

[NOIP2013D2]的更多相关文章

  1. 2018/7/16 YMOI模拟 NOIP2013D2T3华容道

    题目描述 Description 小 B 最近迷上了华容道,可是他总是要花很长的时间才能完成一次.于是,他想到用编程来完成华容道:给定一种局面,华容道是否根本就无法完成,如果能完成,最少需要多少时间. ...

随机推荐

  1. 详解Bootstrap实现基本布局的方法

    看到了一篇 20 分钟打造 Bootstrap 站点的文章,内容有点老,重新使用bootstrap教程实现一下,将涉及的内容也尽可能详细说明. 1. 创建基本的页面我们先创建一个基本的 HTML 模板 ...

  2. ajaxToolkit 异步加载报 错误500的解决方法

    设置IIS程序池的托管模式为经典

  3. 【新特性】JDK1.7

    一.switch中可以使用字串 String s = "test";switch (s) { case "test" :   System.out.printl ...

  4. Nodejs运行错误小结

    (迁移自旧博客2017 04 15) 在使用过程中会遇到一些问题,学习过程中不定期更新. 问题一 错误如下 **events.js:72 throw er; // Unhandled 'error' ...

  5. Largest Rectangular Area in a Histogram 最大连续面积

    在HankerRank遇到一题计算柱状图连续矩形面积的问题. 举例 hist = [3, 2, 3]. 在这个柱状图里面最大可以容纳一个high = 2 length = 3的连续矩形, 其面积 = ...

  6. GTID做mysql主从时报错

    今天在做主从同步时,显示slave_IO线程为NO ,并且报如下错误 Slave_IO_Running: No ... Last_IO_Error: Fatal error: The slave I/ ...

  7. 16_Linux网络配置

    A类:255.0.0.0        8 0 000 0001 - 0 111 1111 127用户回环,1-126 2^7-1个A类地址 容纳多少个主机:2^24-2 主机位全0:网络地址 主机位 ...

  8. 【Git】【环境搭建】

    Mac下GitHub安装及使用教程: https://blog.csdn.net/u012460084/article/details/45830911

  9. (一)为什么要UML

    1 建模的意义 模型是对于现实的简化,建模是为了更好的理解系统 模型帮助我们按照实际情况或需求对系统可视化 模型允许我们详细说明系统的构造,行为 模型给出一个构造系统的模板 模型对我们做出的决策进行文 ...

  10. HDU - 3652

    #include<stdio.h> #include<string.h> #include<math.h> #include<time.h> #incl ...