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. dataguard从库移动数据文件

    ------------方法1从库移动数据文件路径方法1--------------将表空间offline的方法不行 1.退出日志应用alter database recover managed st ...

  2. 物理层PHY 和 网络层MAC

    PHY模块简介 物理层位于OSI最底层,物理层协议定义电气信号.线的状态.时钟要求.数据编码和数据传输用的连接器. 物理层的器件称为PHY. 上图里的灰色方框图里的就是PHY芯片内部模块图. MAC器 ...

  3. topcoder srm 635 div1

    problem1 link 首先枚举长度$L$.然后计算每一段长度$L$的差值最大公约数,然后差值除以最大公约数的结果可以作为当前段的关键字.然后不同段就可以比较他们的关键字,一样就是可以转化的. p ...

  4. 第一次使用eclipse出现的问题

    最近开始学习java,在一系列操作下安装好了eclipse后,按照书上的问题写了一个小程序 问题: 用户从键盘只能输入整数,程序输出这些整数的乘积. 看到这个问题后就感觉和c语言蛮像的,首先去ecli ...

  5. Flask Web框架

    Flask依赖两个外部库:Werkzeug和Jinja2.Werkzeug是一个WSGI(在Web应用和多种服务器之间的标准Python接口)工具集:Jinja2负责渲染模板.所以在安装Flask之前 ...

  6. 史上最全!Selenium元素定位的30种方式

    Selenium对网页的控制是基于各种前端元素的,在使用过程中,对于元素的定位是基础,只有准去抓取到对应元素才能进行后续的自动化控制,我在这里将对各种元素定位方式进行总结归纳一下. 这里将统一使用百度 ...

  7. jQuary学习の五のAJAX

    AJAX 是与服务器交换数据的技术,它在不重载全部页面的情况下,实现了对部分网页的更新. 一.jQuery load() 方法 jQuery load() 方法是简单但强大的 AJAX 方法. loa ...

  8. (转)Extracting knowledge from knowledge graphs using Facebook Pytorch BigGraph.

    Extracting knowledge from knowledge graphs using Facebook Pytorch BigGraph 2019-04-27 09:33:58 This ...

  9. 【Mac】【创建钥匙串】

    1 Mac在钥匙串创建系统证书失败 https://blog.csdn.net/lllkey/article/details/79423596 问题: 在Eclipse的Debug,使用gdb的时候, ...

  10. js switch 用法

    //获取星期 //例子1 var day=new Date().getDay(); switch (day) { : x="Today it's Saturday"; break; ...