【题目链接】:http://codeforces.com/contest/789/problem/C

【题意】



看式子。

【题解】



考虑最后的答案区间;

如果那个区间是从奇数位置的数字开始的;

那么奇数位上的|a[i+1]-a[i]|的系数(-1)^(i-l)就为1否则为-1

如果那个区间是从偶数位置的数字开始的;

那么偶数位….就为-1;

按照这个规则我们处理出b[i]=|a[i+1]-a[i]|

然后分两类处理

一种是偶数位的b[i]为正,奇数位的为负;

另一种是奇数位。。。负。。。。正

然后做最大连续子序列就好了;

这两种情况对应了起点是偶数和奇数的情况;

因为偶数的话,起点肯定是偶数->因为偶数是正的,奇数是负的你肯定一开始先选个正数啊

奇数的话。。起点。。肯定。。



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 1e5+100; int n;
LL a[N],b[N],ans = 0; LL gao()
{
LL ret = 0,ma = 0;
rep1(i, 1, n)
{
if (ret < 0)
ret = b[i];
else
ret = ret + b[i];
ma = max(ma, ret);
}
return ma;
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
rei(n);
rep1(i, 1, n)
rel(a[i]);
rep1(i, 1, n - 1)
{
b[i] = a[i + 1] - a[i];
if (b[i] < 0) b[i] = -b[i];
if ((i % 2) == 0)
b[i] = -b[i];
}
n--,ans = max(ans, gao());
rep1(i, 1, n)
b[i] = -b[i];
ans = max(ans, gao());
cout << ans << endl;
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

【codeforces 789C】Functions again的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 757E】Bash Plays with Functions

    [题目链接]:http://codeforces.com/problemset/problem/757/E [题意] 给你q个询问; 每个询问包含r和n; 让你输出f[r][n]; 这里f[0][n] ...

  3. 【codeforces 604D】Moodular Arithmetic

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  5. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  6. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  7. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  8. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  9. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

随机推荐

  1. [D3] Reuse Transitions in D3 v4

    D3 transitions start executing as soon as they’re created, and they’re destroyed once they end. This ...

  2. shell基础之符号与语法

            shell脚本如今已经成为了一种非常普遍的脚本语言,之所以如此广泛的被应用,毋庸置疑它是有它的独到之处的.shell脚本语言和其它的语言比方说c/c++有何不同呢?c/c++等语言属于 ...

  3. Altium Designer如何统一改变pcb状态下的原件标号位置

    原创 我用的是Altium Designer16版本 变成 步骤如下: 选中标号 右击 下边一步很重要: 点击应用和确定 在之后弹出的对话框中选则你要改变的位置,我这里是把标号改变到原件的右侧: 等待 ...

  4. SQL Server2008 Hierarchyid数据类型

    以往我们在关系数据库中建立树状结构的时候,通常使用ID+ParentID来实现两条 纪录间的父子关系.但这种方式只能标示其相对位置.解决这类问题在SqlServer2005出现之前通常是采用游标来操作 ...

  5. python整除

    1.'/'除号与c不同,单个'/'是浮点除,两个除号'//'才是整除

  6. 【BZOJ 3998】弦论

    [链接]h在这里写链接 [题意]     给你一个长度为n的子串;     让你求出第k小的子串是什么;     输出答案的类型分两种;     第一种,重复的算两次,第二种,重复的算一次.     ...

  7. 11、V4L2摄像头获取单幅图片测试程序

    #根据网上常见的一个测试程序修改而来 by rockie cheng#include <stdio.h>#include <stdlib.h>#include <stri ...

  8. 29、应用调试之使用GDB来调试应用程序

    说明:gdb可以实现源代码单步调试 原理: 1.gdb在PC机上运行,gdbserver在arm开发板上运行,gdbserver在开发板上相当于父进程,应用相当于子进程,PC上gdb发命令给gdbse ...

  9. [Angular] @ContentChild with Directive ref

    For example you have a component, which take a trasclude input element: <au-fa-input id="pas ...

  10. [Angular2 Form] Validation message for Reactive form

    <div class="form-field"> <label>Confirm Password: </label> <input typ ...