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. postgresql开启网络连接

    默认情况下,postgresql是只允许localhost连接的,如果需要使用远程连接,需要修改两个配置文件. postgresql.conf 和 pg_hba.conf 在postgresql.co ...

  2. 16: mint-ui移动端

    1.1 mint-ui安装与介绍  官网:http://mint-ui.github.io/docs/#/zh-cn2/loadmore 1.安装与引用 // 安装Vue 2.0 npm instal ...

  3. PKUWC 2017 Day 2 简要题解

    *注意:题面请移步至loj查看. 从这里开始 Problem A 随机算法 Problem B 猎人杀 Problem C 随机游走 怎么PKU和THU都编了一些假算法,然后求正确率[汗]. 之前听说 ...

  4. 字符和字符串在Java中的旅程

    以下是个人对java中字符和字符串的见解,如有疏漏之处,还请不吝赐教. 下面通过一个简单的程序来说明字符和字符串在Java中的旅程. 以字符 ' 中 '为例, 它的GBK编码是2个字节:0xd6d0, ...

  5. EmberJS 为什么我偏爱 Ember.js 胜过 Angular 和 React.js

    文章写的很老到,非常值得一看!评论也很精彩,值得一看 为什么我偏爱 Ember.js 胜过 Angular 和 React.js 前几天看到了这篇文章:Why I prefer Ember.js ov ...

  6. 20165306 Exp4 恶意代码分析

    Exp4 恶意代码分析 一.实践概述 1.实践目标 1.1是监控你自己系统的运行状态,看有没有可疑的程序在运行. 1.2是分析一个恶意软件,就分析Exp2或Exp3中生成后门软件:分析工具尽量使用原生 ...

  7. Sonar 配置及部署(windows系统)

    Sonar 是一个用于代码质量管理的开放平台.通过插件机制,Sonar 可以集成不同的测试工具,代码分析工具,以及持续集成工具. 与持续集成工具(例如 Hudson/Jenkins 等)不同,Sona ...

  8. mybatis中mapper接口的参数设置几种方法

    方法一:忽略parameterType,加@param("xxx")注解 在mapper接口中加上@param("xxx")注解,则在配置文件中直接用即可 Li ...

  9. lua相关的小知识

    lua的特性 1. 轻量级:一标准的C语言编写原发开放,编译后仅仅100K,占用内存小: 2. 扩展性:Lua提供了非常已于使用的扩展口和机制: 3. 支持面向过程编程和函数式编程 lua的数据类型 ...

  10. put与putIfAbsent区别

    put与putIfAbsent区别: put在放入数据时,如果放入数据的key已经存在与Map中,最后放入的数据会覆盖之前存在的数据, 而putIfAbsent在放入数据时,如果存在重复的key,那么 ...