[CH0304]IncDec Sequence
和NOIP2018DAY1T1类似的题目,但思维难度高多了。
这题既可以抬高路面,也可以降低路面,而且目标平面不确定,就难起来了。
但是两道题的基本思路几乎一样,同样我们将 2~n 的高度差分,1之所以不要差分是因为最终的高度是不确定的。
所以现在的目标就是将这个差分数组的任意一个位置 +1/-1 ,另一个位置 -1/+1,使 2~n 的差分数组变成 0,显然最少次数就是 max(正数之和,负数绝对值之和) 。
第二问要求最终的可能平面有多少种,考虑操作的过程中当正的或负的已经被搞成 0 ,只剩一部分负的或正的,那这对应原来的数组就是从 2~n 单调的,所以1的取值只能在最高点和最低点之间,这样才能保证次数最少,答案就是 abs(正数之和 - 负数绝对值之和) + 1
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <assert.h>
#include <algorithm>
using namespace std;
#define LL long long
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define GO debug("GO\n")
inline int rint() {
register int x = 0, f = 1; register char c;
while (!isdigit(c = getchar())) if (c == '-') f = -1;
while (x = (x << 1) + (x << 3) + (c ^ 48), isdigit(c = getchar()));
return x * f;
}
template<typename T> inline void chkmin(T &a, T b) { a > b ? a = b : 0; }
template<typename T> inline void chkmax(T &a, T b) { a < b ? a = b : 0; }
#define int LL
signed main() {
#ifndef ONLINE_JUDGE
freopen("xhc.in", "r", stdin);
freopen("xhc.out", "w", stdout);
#endif
int n;
cin >> n;
int x = 0, y = 0, last, now;
cin >> last;
for (int i = 2; i <= n; ++ i) {
cin >> now;
if (now > last) y += now - last;
else x += last - now;
last = now;
}
cout << max(x, y) << endl << abs(y - x) + 1 << endl;
return 0;
}
[CH0304]IncDec Sequence的更多相关文章
- CH-0304 IncDec Sequence
0304 IncDec Sequence 0x00「基本算法」例题 描述 给定一个长度为 n(n≤10^5 ) 的数列 {a_1,a_2,…,a_n},每次可以选择一个区间 [l,r],使下标在这个区 ...
- bzoj 3043: IncDec Sequence 模拟
3043: IncDec Sequence Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 248 Solved: 139[Submit][Statu ...
- Poetize6: IncDec Sequence
3043: IncDec Sequence Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 233 Solved: 132[Submit][Statu ...
- 前缀和与差分之IncDec sequence
参考链接:https://blog.csdn.net/hzk_cpp/article/details/80407014 题目链接:https://www.acwing.com/problem/cont ...
- 【BZOJ 3043】 3043: IncDec Sequence (差分)
3043: IncDec Sequence Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 589 Solved: 332 Description 给 ...
- 【BZOJ3043】IncDec Sequence 乱搞
[BZOJ3043]IncDec Sequence Description 给定一个长度为n的数列{a1,a2...an},每次可以选择一个区间[l,r],使这个区间内的数都加一或者都减一.问至少需要 ...
- BZOJ 3043: IncDec Sequence
3043: IncDec Sequence Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 578 Solved: 325[Submit][Statu ...
- 2498 IncDec Sequence
2498 IncDec Sequence 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description 给 ...
- 差分:IncDec Sequence 差分数组
突然就提到了这个东西,为了不再出现和去年联赛看见二分没学二分痛拿二等第一的情况,就去学了一下,基础还是比较简单的-- 先看一个经典例题: 给定一个长度为n的数列{a1,a2...an},每次可以选择一 ...
随机推荐
- Unity 游戏框架搭建 (二十三) 重构小工具 Platform
在日常开发中,我们经常遇到或者写出这样的代码 var sTrAngeNamingVariable = "a variable"; #if UNITY_IOS || UNITY_AN ...
- Oracle创建表、修改表、删除表、约束条件语法
一. 使用create关键字创建表 --(1)创建新表use 数据库(在那个数据库中建表)create table 表名(字段名1(列名) 数据类型 列的特征,字段名2(列名) 数据类型 列的特征(N ...
- 用java数组模拟登录和注册功能
package com.linkage.login; import java.util.Scanner; public class user { // 存储用户名和密码 public static S ...
- you don't have permission to access ...........on this server问题解决
因为刚刚开始使用新架构的项目,于是把老项目统统替换成了新的项目.配置好后,本地登录页面报 you don't have permission to access ...... on this serv ...
- 日期格式操作,在oracle和mysql中的实现
oracle add_months(日期格式值 , 整数n) 当整数n=12时,代表一年,向后推迟一年,若n=-12代表回退一年 如 to_char(add_months(to_date('2018 ...
- linux下pip错误 ImportError: No module named 'pip_internal'
wget https://bootstrap.pypa.io/get-pip.py --no-check-certificate sudo python get-pip.py
- 第3章 Hadoop 2.x分布式集群搭建
目录 3.1 配置各节点SSH无密钥登录 1.将各节点的秘钥加入到同一个授权文件中 2.拷贝授权文件到各个节点 3.测试无秘钥登录 3.2 搭建Hadoop集群 1.上传Hadoop并解压 2.配置H ...
- Python学习 :函数
函数 函数(Functions) 是指可重复使用的程序片段.它们允许你为某个代码块赋予名字,允许你通过这一特殊的名字在你的程序任何地方来运行代码块,并可重复任何次数.这就是调用(Calling)函数. ...
- day2-exercise
# Author: 刘佳赐-Isabelle October 22,2018 """ 1.有变量name = "aleX leNb" 完成如下操作: ...
- 04IP编址(网络层)
帧中type为0x0800,送给ip ip报文结构 TTL 生存时间最大为255,经过三层设备就减1 protocol:协议号 version:4,6 source ip address:源ip编 ...