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. xampp——apache服务启动问题(端口占用)

    Apache启动提示 20:39:02 [Apache] Error: Apache shutdown unexpectedly.20:39:02 [Apache] This may be due t ...

  2. spring-data-jpa中save不触发数据库insert语句的问题

    最近学习spring mvc,用到jpa简化DAO层代码,发现save死活不触发SQL语句,找了好久才解决这个问题,实在是坑.. <!-- 关键是这个bean,一定要设置正确才行 --> ...

  3. lsyncd+rsync配置图片资源双向同步

    需求:为保证国内外图片加载速度,国内请求上传图片资源地址阿里云oss,国外请求上传图片资源地址aws s3,为保证图片资源的一致性,需定时进行oss和s3图片双向同步 调研方案:由于之前配置过inot ...

  4. ASP.NET Core开发总结

    1.关于浏览器缓存,修改CSS文件和Javascript文件后调试,浏览器不更新问题,解决办法是在link标签和script标签引用的文件名后面添加版本信息如下: <link rel=" ...

  5. 富文本编辑器Quill(一)简单介绍

    Quill是一个很流行的富文本编辑器,github上star大约21k: github:https://github.com/quilljs/quill/ 官网: https://quilljs.co ...

  6. Java多线程的创建与简单使用

    一.线程的基本概念 什么是线程:Thread 进程内部的一个执行单元,它是程序中一个单一的顺序控制流程. 线程又被称为轻量级进程(lightweight process) 如果在一个进程中同时运行了多 ...

  7. P2178 [NOI2015]品酒大会

    思路 在后缀树上进行一些操作就好了 后缀树上LCA的maxlen就是两个后缀的LCP的长度了 然后统计每个点作为LCA的次数和最大值.次大值.最小值.次小值 然后就做完了 代码 #include &l ...

  8. [IoC容器Unity]第四回:使用范例

    1.引言 前面几个章节介绍了Unity的基本使用,主要分为程序和配置文件两种方法的使用,可以参考一下链接, [IoC容器Unity]第一回:Unity预览 [IoC容器Unity]第二回:Lifeti ...

  9. KAFKA跨主机部署网络不通解决思路

    Kafka的部署不仅需要集群可用,同时需要对orderer节点可连,这就是为什么有的时候,kafka集群本身没问题,但是orderer却总是报错. 为了试验kafka剥离方案的可行性,跨阿里云网络和内 ...

  10. _spellmod_aura_pct_on_stat

    为玩家添加属性转换光环 `comment` 备注 `aura`光环ID `auraType1` 选择添加('治疗效果','法术强度','近战攻击强度','远程攻击强度','空')  `statType ...