AT5221 [ABC140C] Maximal Value 题解
Content
有一个长度为 \(n\) 的数列 \(A\) 未知,已知一个数列 \(B=\{b_1,b_2,...,b_{n-1}\}\),且满足 \(b_i\geqslant \max\{a_i,a_{i+1}\}\)。求原数列 \(A\) 的元素和的最大值。
数据范围:\(n\in[2,100],b_i\in[0,10^5]\)。
Solution
很显然,\(a_i\) 的最大值为 \(\min\{b_i,b_{i-1}\}\),所以先逐个更新 \(a_i\),然后直接求和即可。
Code
int n, b[107], a[107];
int main() {
n = Rint;
memset(a, 0x3f, sizeof(a));
F(i, 1, n - 1) {
b[i] = Rint;
a[i] = min(a[i], b[i]), a[i + 1] = b[i];
}
int sum = 0;
F(i, 1, n) sum += a[i];
return printf("%d\n", sum), 0;
}
AT5221 [ABC140C] Maximal Value 题解的更多相关文章
- 算法与数据结构基础 - 数组(Array)
数组基础 数组是最基础的数据结构,特点是O(1)时间读取任意下标元素,经常应用于排序(Sort).双指针(Two Pointers).二分查找(Binary Search).动态规划(DP)等算法.顺 ...
- LeetCode题解:(221) Maximal Square
题目说明 Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's a ...
- LeetCode85 Maximal Rectangle java题解
public static int maximalRectangle(char[][] matrix) { int rowNum=matrix.length; if(rowNum==0) return ...
- 题解 [CF803C] Maximal GCD
题面 解析 一开始以为这题很难的... 其实只要设\(d\)为\(a\)的最大公因数, 即\(a[i]=s[i]*d\), 因为\(n=\sum_{i=1}^{n}a[i]=\sum_{i=1}^ns ...
- 题解 CF803A Maximal Binary Matrix
Luogu codeforces 前言 模拟赛原题.. 好好一道送分被我硬打成爆蛋.. \(\sf{Solution}\) 看了一波数据范围,感觉能 dfs 骗分. 骗成正解了. 大概就是将这个 \( ...
- 求解最大矩形面积 — leetcode 85. Maximal Rectangle
之前切了道求解最大正方形的题,题解猛戳 这里.这道题 Maximal Rectangle 题意与之类似,但是解法完全不一样. 先来看这道题 Largest Rectangle in Histogram ...
- LeetCode OJ 题解
博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-S ...
- LeetCode Maximal Square
原题链接在这里:https://leetcode.com/problems/maximal-square/ 这是一道DP题,存储历史信息是到当前点能有的最大square, 用二维数组dp存储. 更新方 ...
- 2014年亚洲区域赛北京赛区现场赛A,D,H,I,K题解(hdu5112,5115,5119,5220,5122)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 下午在HDU上打了一下今年北京区域赛的重现,过了5题,看来单挑只能拿拿铜牌,呜呜. ...
随机推荐
- request.setAttribute()和session.setAttribute()的区别详解
我们在Servlet和页面间传值时,经常会用到request.setAttribute()和session.setAttribute(),下面是两段示例用法 request.setAttribute( ...
- vue 3 学习笔记 (八)——provide 和 inject 用法及原理
在父子组件传递数据时,通常使用的是 props 和 emit,父传子时,使用的是 props,如果是父组件传孙组件时,就需要先传给子组件,子组件再传给孙组件,如果多个子组件或多个孙组件使用时,就需要传 ...
- Apache ShardingSphere 5.0.0 内核优化及升级指南
经过近两年时间的优化和打磨,Apache ShardingSphere 5.0.0 GA 版终于在本月正式发布,相比于 4.1.1 GA 版,5.0.0 GA 版在内核层面进行了大量的优化.首先,基于 ...
- 【CSP2019】【洛谷5657】格雷码
传送门:https://www.luogu.com.cn/problem/P5657 题意不再复述: 我们知道对于每个字符1 or 0: 只要考虑当前的k在2^n的前半段还是后半段就行 这里需要注意的 ...
- 如何根据fasta快速统计基因组大小及其各染色体长度?
基因组长度 利用seqkit统计长度 seqkit stat test.fa 结果如下: file format type num_seqs sum_len min_len avg_len max_l ...
- 【机器学习与R语言】1-机器学习简介
目录 1.基本概念 2.选择机器学习算法 3.使用R进行机器学习 1.基本概念 机器学习:发明算法将数据转化为智能行为 数据挖掘 VS 机器学习:前者侧重寻找有价值的信息,后者侧重执行已知的任务.后者 ...
- LetNet、Alex、VggNet分析及其pytorch实现
简单分析一下主流的几种神经网络 LeNet LetNet作为卷积神经网络中的HelloWorld,它的结构及其的简单,1998年由LeCun提出 基本过程: 可以看到LeNet-5跟现有的conv-& ...
- 【模板】有源汇有上下界最大流(网络流)/ZOJ3229
先导知识 无源汇有上下界可行流 题目链接 https://vjudge.net/problem/ZOJ-3229 https://www.luogu.com.cn/problem/P5192 (有改动 ...
- MPI 学习笔记
目录 MPI学习笔记 MPI准备 概述 前置知识补充 环境部署 1.修改IP及主机名 2.关闭防火墙 3.实现免密码SSH登录 4.配置MPI运行环境 5.测试 程序的执行 编译语句 运行语句 MPI ...
- 【leetcode】378. Kth Smallest Element in a Sorted Matrix(TOP k 问题)
Given an n x n matrix where each of the rows and columns is sorted in ascending order, return the kt ...