Codeforces788A Functions again 2017-04-12 18:22 56人阅读 评论(0) 收藏
1 second
256 megabytes
standard input
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.
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.
Print the only integer — the maximum value of f.
5
1 4 2 3 1
3
4
1 5 4 7
6
——————————————————————————————————————
题目的意思是选取一段区间,使得满足关系式的值最大
思路:观察关系式我们可以知道,它由相邻两项之差,由某项开始奇数项取正偶数项取负求和而得,我们可以预处理出相邻的差,构造两个序列,一个奇正偶负,一个相反,然后求最大字段和
#include <iostream>
#include<queue>
#include<cstdio>
#include<cmath>
#include<set>
using namespace std;
#define LL long long
LL a[100005];
LL b[100005];
LL c[100005]; int main()
{
int n;
scanf("%d",&n);
for(int i=0; i<n; i++)
{
scanf("%lld",&a[i]);
}
for(int i=1; i<n; i++)
{
LL x=fabs(a[i]-a[i-1]);
if(i%2) b[i]=x;
else b[i]=-x;
c[i]=-b[i];
}
LL s=0,mx=0;
for(int i=1; i<n; i++)
{
if(s+c[i]<0) s=0;
else s+=c[i];
if(s>mx) mx=s;
}
s=0;
for(int i=1; i<n; i++)
{
if(s+b[i]<0) s=0;
else s+=b[i];
if(s>mx) mx=s; }
printf("%lld\n",mx);
return 0;
}
Codeforces788A Functions again 2017-04-12 18:22 56人阅读 评论(0) 收藏的更多相关文章
- Doubles 分类: POJ 2015-06-12 18:24 11人阅读 评论(0) 收藏
Doubles Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19954 Accepted: 11536 Descrip ...
- highgui.h备查 分类: C/C++ OpenCV 2014-11-08 18:11 292人阅读 评论(0) 收藏
/*M/////////////////////////////////////////////////////////////////////////////////////// // // IMP ...
- 移植QT到ZedBoard(制作运行库镜像) 交叉编译 分类: ubuntu shell ZedBoard OpenCV 2014-11-08 18:49 219人阅读 评论(0) 收藏
制作运行库 由于ubuntu的Qt运行库在/usr/local/Trolltech/Qt-4.7.3/下,由makefile可以看到引用运行库是 INCPATH = -I/usr//mkspecs/d ...
- iOS开发:创建真机调试证书 分类: ios相关 2015-04-10 10:22 149人阅读 评论(0) 收藏
关于苹果iOS开发,笔者也是从小白过来的,经历过各种困难和坑,其中就有关于开发证书,生产证书,in_house证书,add_Hoc证书申请过程中的问题,以及上架发布问题.今天就着重说一下关于针对于苹果 ...
- iOS 消息推送原理及实现总结 分类: ios技术 2015-03-01 09:22 70人阅读 评论(0) 收藏
在实现消息推送之前先提及几个于推送相关概念,如下图: 1. Provider:就是为指定IOS设备应用程序提供Push的服务器,(如果IOS设备的应用程序是客户端的话,那么Provider可以理解为服 ...
- Rebuild my Ubuntu 分类: ubuntu shell 2014-11-08 18:23 193人阅读 评论(0) 收藏
全盘格式化,重装了Ubuntu和Windows,记录一下重新配置Ubuntu过程. //build-essential sudo apt-get install build-essential sud ...
- HDU6023 Automatic Judge 2017-05-07 18:30 73人阅读 评论(0) 收藏
Automatic Judge Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- How to create your own custom 404 error page and handle redirect in SharePoint 分类: Sharepoint 2015-07-08 00:22 4人阅读 评论(0) 收藏
1. In your MOSS server, make a copy of %systemdrive%\Program Files\Common Files\Microsoft Shared\Web ...
- *** glibc detected *** malloc(): memory corruption 分类: C/C++ Linux 2015-05-14 09:22 37人阅读 评论(0) 收藏
*** glibc detected *** malloc(): memory corruption: 0x09eab988 *** 发现是由于memset越界写引起的. 在Linux Server上 ...
随机推荐
- popup控件代码示例
1.jsp页面input框中的代码 <td class="value"> <input name="demos[0].id" type=&qu ...
- Non-standard evaluation, how tidy eval builds on base R
As with many aspects of the tidyverse, its non-standard evaluation (NSE) implementation is not somet ...
- windows 内存分配回收检查工具
LeakDiag是微软一款检测memory leak的工具,使用比较简单 首先去下载一个ftp://ftp.microsoft.com/PSS/Tools/Developer%20Support%20 ...
- 黄聪:将自己开发的插件发布到WordPress官方插件站(转)
原文作者:我爱水煮鱼 把你的插件发布到 WordPress 官方插件目录是让更多人用到插件的好方法,这样可以让你的插件不仅仅给我们中国人民使用,而且还可以让你的插件给全世界人民使用,想想全世界人民都在 ...
- 使用用WCF中的双工(Duplex)模式将广告图片推送到每个Winform客户端机子上
参考资料地址:http://www.cnblogs.com/server126/archive/2011/08/11/2134942.html 代码实现: WCF宿主(服务端) IServices.c ...
- ffmpeg+nginx+video实现rtsp流转hls流,通过H5查看监控视频
一.FFmpeg下载:http://ffmpeg.zeranoe.com/builds/ 下载并解压FFmpeg文件夹,配置环境变量:在“Path”变量原有变量值内容上加上d:\ffmpeg\bin, ...
- 去掉Linux尖锐的提示音
新装CentOS7,Tab键没有结果的时候,总是有尖锐的提示音,下面是如何去除这个提示音: # /etc/inputrc 找到 ‘#set bell-style none’,去掉注释# # reboo ...
- Centos编译Redis4.0.9源码过程记录
mkdir /home/redis cd /home/redis 下载源码 wget https://codeload.github.com/antirez/redis/tar/4.0.9 解压源码包 ...
- oracle事务知识点小结
DML语句流程 1 获取事务锁和ITL2 锁定候选行3 生成redo4 生成undo5 生成redo record写入log buffer并更改数据块 事务提交1 分配SCN2 更新事务表,将事务槽状 ...
- 传统项目利用Hystrix实现热点接口的服务隔离
这段时间接了个需求,需要在我目前负责的数据系统上加个接口,主要是实现用户行为的记录.前端对接的项目主要有公司的PC,WAP,WEIXIN,APP等,每个端大概有两台左右的负载.因为目前我的这个项目主要 ...