[NOIP2013D2]
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]的更多相关文章
- 2018/7/16 YMOI模拟 NOIP2013D2T3华容道
题目描述 Description 小 B 最近迷上了华容道,可是他总是要花很长的时间才能完成一次.于是,他想到用编程来完成华容道:给定一种局面,华容道是否根本就无法完成,如果能完成,最少需要多少时间. ...
随机推荐
- Linux nmcli 网络管理
Linux nmcli 网络管理 RHEL 和 CentOS 系统默认使用 NetworkManager 来提供网络服务,这是一种动态管理网络配置的守护进程,能够让网络设备保持连接状态.可以使用 nm ...
- Pdf Convert Image 的解决方案
brew uninstall ghostscript brew install ghostscript gs -dNOPAUSE -sDEVICE=jpeg -r150 -sOutputFile=./ ...
- 微信小程序表单验证
参考:http://www.cnblogs.com/zhangxiaoyong/p/10166951.html
- vueRouter 子路由嵌套
router.js import Vue from 'vue' import Router from 'vue-router' import contractPage from './views/co ...
- qt部件的可视性
- 我应该如何在Pycharm中去运行别人的Django项目
django数据库迁移,本地运行 前言: 从网络上下载好django项目后,在本地用pycharm导入后,并不能运行.此时我们需要添加库和创建数据库. 零:这里是一个基于django写的小项目,可以作 ...
- Vue学习(一)Vue目录结构
安装教程网上一大把,可以自己搜索.记录下学习过程. 认识下Vue的目录结构,取自:https://www.cnblogs.com/dragonir/p/8711761.html vue 文件目录结构详 ...
- 【codeforces 242E】XOR on Segment
[原题题面]传送门 [题面翻译]传送门 [解题思路] 操作涉及到区间求和和区间异或,考虑到异或操作,我们对每个数二进制分解. 把每一位单独提出来做,异或要么取反要么变为不变,对于每一位建一颗线段树,那 ...
- 支持向量机(Support Vector Machine):超平面
超平面 超平面是 $n$ 维空间的 $n-1$ 维子空间,类似二维空间的直线,三维空间的平面. 分类学习最基本的想法就是基于训练集D在样本空间中找到一个划分超平面,将不同类别的样本分开.以二维空间为例 ...
- python实现将base64编码的图片下载到本地
# -*- coding:utf-8 -*- #!python3 import os import base64 sss ="""base64的编码"" ...