Codeforces Round #407 (Div. 2) C. Functions again(最大连续子段和)

分享一下如何使用labelimg制作自己的YOLO数据集 首先准备一下自己的下准备一个空文件夹用于保存标签文件,如下图所示。 阅读详情

题目地址:点击打开链接


思路:一共就两种情况,要么奇数位为负,要么偶数位的为负。两个分别求下最大连续子段和取较大值就行。


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
ll a[maxn], v[maxn], n;

int main(void)
{
    while(cin >> n)
    {
        for(int i = 1; i <= n; i++)
            scanf("%I64d", &a[i]);
        for(int i = 1; i < n; i++)
            v[i] = abs(a[i+1]-a[i]);
        ll ans = 0;
        for(int i = 1; i < n; i++)
            a[i] = i%2 ? -v[i] : v[i];
        ll tmp = 0;
        for(int i = 1; i < n; i++)
        {
            tmp += a[i];
            if(tmp < 0) tmp = 0;
            ans = max(ans, tmp);
        }
        for(int i = 1; i < n; i++)
            a[i] = i%2 ? v[i] : -v[i];
        tmp = 0;
        for(int i = 1; i < n; i++)
        {
            tmp += a[i];
            if(tmp < 0) tmp = 0;
            ans = max(ans, tmp);
        }
        cout << ans << endl;
    }
    return 0;
}

C. Functions again
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:

In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.

Input

The first line contains single integer n (2 ≤ n ≤ 105) — the size of the array a.

The second line contains n integers a1, a2, ..., an (-109 ≤ ai ≤ 109) — the array elements.

Output

Print the only integer — the maximum value of f.

Examples
input
5
1 4 2 3 1
output
3
input
4
1 5 4 7
output
6
Note

In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].

In the second case maximal value of f is reachable only on the whole array.



【Altium designer】如何添加过孔阵列 按下图1指示,执行【Tool】菜单栏下【Via Stitching/Shielding】选项卡中的【Add Stitching to Net...】选项 图1 “添加过孔阵列”选项 点击【Add Stitching to Net...】选项后,会跳出一个窗口,让我们设置过孔阵列的参数信息,如下图2所示。 图2 过孔阵列参数设置 过孔阵列区域:勾选该选项框,即可绘制多边形区域; 过孔内径与焊盘直径:比如内径 【Hole Size】设为12mil,焊盘直径【Diameter】设为24mil; . 阅读详情

相关推荐

YOLO11实战:手把手教你优化钢材表面缺陷识别模型(基于NEU-DET数据集)

本文详细介绍了如何使用YOLO11优化钢材表面缺陷识别模型,基于NEU-DET数据集进行实战训练。从数据增强、模型架构优化到训练过程控制,全面解析提升钢材缺陷检测性能的关键技术,特别针对裂纹、划痕等典型缺陷提出针对性解决方案。

weixin_29081163的博客 386

codeforces 722C Destroying Array ( 并查集 / Multiset )

题目大意 : 给定一个乱序的数列,每次从中删去一个元素(留下空位),问剩下的连续子段和(中间不包括被删除的元素)的最大值。 解题思路: 1、正向思维:也就是正向模拟这个过程,考虑如何实现,一个Multiset保存当前所有的连续字段和,另开一个set保存每一段闭区间,要保证每次切断一个区间,加两个新区间进去,删去一个当前的连续字段和,加上两个心得连续字段和。 2、逆向思维:如果正向进行这个

wchhlbt的博客 526

飞傲Fiio+foobar2000 实现dsd解码+灯正常显示

飞傲Fiio+foobar2000 实现dsd解码+灯正常显示。安装后可将DSD格式的数据通过ASIO驱动传输至DAC。安装后可识别DAC的ASIO驱动。安装后可识别DSD文件。

yanlei7993的博客 2309

Codeforces Round 881 (Div. 3)F1题解

Codeforces Round 881 (Div. 3)F1题解,采用了树形DP的方法

ChuRi_BaiYu的博客 211

生信入门第七课:使用FastQC软件进行测序原始fastq数据质控

从实验到数据:RNA定量、文库片段长度、fastqc质控和fastp去接头

微生信 497

树莓派与无人机协同实战:基于OpenCV的地标识别优化策略

本文深入探讨了基于树莓派与无人机的协同系统,重点分享了利用OpenCV优化地标识别以实现精准降落的实战策略。内容涵盖从应对复杂光照的图像预处理、鲁棒的轮廓几何过滤,到通过ROS进行稳定通信,以及实现分层控制与状态机设计,旨在提升系统在真实环境中的可靠性与性能。

y2z3a4b5c的博客 1092

Codeforces Round #407 (Div. 2)

这次做了2题。A和C。弱鸡rating终于上1400了。 B题看描述觉得大概是数学题,所以连看都没看。 做了A题后,大概15min后发现我居然跑了600ms,觉得终测一定会TLE,所以重新做了。 看到BC过的人很少,没信心,直接LOCK了A去hack。 看到一个可以hack,但说我数据太大,提交不上去(我并不知道可以提交文件)所以没hack。 以后不这样来了,努力做题才是正事啊...(hack浪费

zehong1995的博客 189

Tessent --- PDL

当关联的ICL模块是当前ICL顶部模块时,即当它与当前设计匹配时,只能iCall一个iTopProc。但是,可以在iTopProc内调用iCall iProc或iTopProc。为指定后续iProc命令引用的ICL模块,发出这个命令之后,随后定义的iProc都会对应的ICL模块进行定义。为后续iCall调用,当使用iCall命令调用该过程时,参数列表中的变量将被替换为iCall命令中指定的值。在调用iProc时,运行iProc内的命令。PDL是面向工程师的,工程师利用PDL语言,对ICL中的单元进行控制。

qiantianyiqian的博客 2809

Codeforces Round #407 (Div. 2) C.Functions again(789C)

题目大意:对于N个数,选定其中的【L,R】的数, 使得|a[l+1]-a[l]|-|a[l+2]-a[l+3]|+….+|a[r-1]-a[r-2]|-|a[r]-a[r-1]|最大; 其实就是每两个数做差,得到一个n-1长度的序列b,然后对序列b的【L,R】区间里,从L开始数第一项以及后面的奇

ddjing_的博客 441

【Docker】完美解决拉取镜像超时报错:ERROR: Get https://registry-1.docker.io/v2/

因为我们下载的镜像是外网的镜像资源,所以下载的速度会非常的慢,甚至大概率下载时会报错,所以需要我们配置一个国内的服务器镜像地址,国内服务器镜像地址有很多,这里咱们就说一下阿里镜像加速器的配置方法。

liu_chen_yang的博客 12万+

【雕爷学编程】Arduino动手做(111)---震动提醒模块

37款传感器与执行器的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止这37种的。鉴于本人手头积累了一些传感器和执行器模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里准备逐一动手尝试系列实验,不管成功(程序走通)与否,都会记录下来---小小的进步或是搞不掂的问题,希望能够抛砖引玉。

雕爷学编程 1900

Codeforces Round #407 Functions again(dp,贪心)

C. Functions again time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Something happened in Uzhlyandia again...

spark__s的博客 516

Buck电源设计常见的一些问题(五)MOS管振荡抑制方法(三)

关于开关节点振荡的产生机制和抑制问题,总结了三种抑制方法。第一种方法是利用输入端的高频去耦电容;第二种方法是设计 RC 缓冲电路;第三种方法是优化自举电路的串联电阻。以上三种方法均通过实验加以验证,对开关节点振荡具有很好的抑制作用。应该综合同步 Buck 变换器的各项指标权衡设计。

小幽余生不加糖 1637

codeforces Codeforces Round #407 Div2题解 B,C,D,E

题目链接:about:http://codeforces.com/contest/789B仔细想一想,对于一个l r 区间的最大值,其实就是求一个最大连续子序列。不过这个地方有点特殊,区间都是以开头为正数的。然后正负正负。但仔细想想就会发现其实就只有两种情况:对于这整个差的绝对值得序列:1.正负正负…….2.负正负正……所以我们构造这样的两个序列,求这两个序列的最大子序列。 . Masha a

now_ing的博客 293

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

Codeforces Round #407 (Div. 2) C. Functions again【最大子段和】

C. Functions again time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Something happened in Uzhlyandia again...

Haipai1998的博客 219

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

Codeforces Round #407 (Div. 2) C. Functions again

题目链接:http://codeforces.com/contest/789/problem/C题目就是求最大连续子序列,但是从起点开始,数字都是一正一负, 需要可以分成奇数位和偶数位开始 两种情况。 这里还需要注意的是用int64,不然会爆掉。#include <stdio.h> #include <ctype.h> #include <string.h> #include <stdlib.h

a342500329a的专栏 286

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Codeforces Round #407(Div. 2)C. Functions again【思维+最大连续子序列的和】

C. Functions again time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Something happened in Uzhlyandia again...

mengxiang000000 485

Codeforces Round #407 C. Functions again (前缀和)

C. Functions again题意给定有 n 个元素的数组 a 以及公式 f(l,r)=Σr−1i=l∣a[i]−a[i+1]∣⋅(−1)i−lf(l, r)=\Sigma_{i=l}^{r-1}\mid a[i]-a[i+1]\mid \cdot (-1)^{i-l} 。求在 1≤l<r≤n1\le l \lt r \le n 的情况下,最大的 f(l,r)f(l, r) 。解题思路此题可以

DorMOUSENone的博客 624

Codeforces Round #407 (Div. 2) C. Functions again(前缀和)

C. Functions again time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Something happened in Uzhlyandia again… There are riots on the streets…

妍恐龙的博客....^~^眼熟我 651

Codeforces Round #407 (Div. 2) C Functions again(最大子序列和)

Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the a...

weixin_30508241的博客 147

Codeforces Round #407 C.Functions again

预处理后 居然没发现从odd开始和从even开始的每一项符号是相反的。。。 转载于:https://www.cnblogs.com/xsthunder/p/6657846.html

aigu4729的博客 110

Lightoj 1011 Marriage Ceremonies(状压dp入门 or km板子)

题意:给你n*n的矩阵,a[i][j]代表第i个男人和第j个女人之间的满意度,求男女一一配对后,最大的满意度之和。(n 思路:可以直接套KM板子,n^3复杂度,因为n比较小,也可以用状压做,n^2*2^n复杂度 转移方程:dp[i][sta|(1 代码: #include using namespace std; const int maxn = 17; int dp[ma

CillyB的博客 3024

2017 ACM-ICPC 亚洲区(青岛赛区)网络赛 HDU 6212 1007 Zuma (区间DP)

题意:给你一串01串,你可以在任意位置插入0或1,有三个及以上的连续的相同的会消去,会有连锁反应,问至少插 入几次能消完。 思路:原题。。BZOJ 1032// POJ 2915。。 解法可以看这篇文章:点击打开链接 代码(直接用了这份:点击打开链接): #include using namespace std; int p[26]; int colors[26]

CillyB的博客 2427

第十四届浙江省赛 ZOJ 3962 Seven Segment Display(数位DP)

Seven Segment Display Time Limit: 1 Second      Memory Limit: 65536 KB A seven segment display, or seven segment indicator, is a form of electronic display device for displaying decimal numera

CillyB的博客 2339

之江学院2017ACM校赛 Problem B: qwb与矩阵(记忆化搜索)

题意:(n, m)的迷宫,每个点都有一个值,从(1, 1)走到(n, m) 有三种走法:移动到(x+1,y),(x,y+1)或者(x,y*k),其中k>1,问走到(n,m)的最大价值。 思路:和HDU1078很像,记忆化搜索就行。 代码: #include #include #include using namespace std; const int maxn = 25;

CillyB的博客 1606

Gym 100792H Hashing (DP)

题意:给你n个1个字节的数(16进制表示)(n 0^s[0]+1^s[1]+2^s[2]+…k^s[k]的和最大, k任意,输出这个和的最大值。 思路:懒得写了,,粘贴这位大佬的(点击打开链接)。。讲的很详细 第一步: 首先很容易想到一个简单的dp方程 dp[i][j] = max(dp[i-1][j], dp[i-1][j-1]+(arr[i]^j))

CillyB的博客 1074
上一篇: HDU 5418 Victor and World (状压DP入门)
下一篇: QDUOJ 37 帅气的HYC的珍珠(树状数组)
cillyb
博客等级 码龄11年 225粉丝 497原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值