【题目链接】: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. 通过WMI的方式去设置LCD背光亮度

    code例如以下: #include "stdafx.h" #include <objbase.h> #include <windows.h> #inclu ...

  2. POJ 3723 Conscription MST

    http://poj.org/problem?id=3723 题目大意: 需要征募女兵N人,男兵M人,没征募一个人需要花费10000美元,但是如果已经征募的人中有一些关系亲密的人,那么可以少花一些钱, ...

  3. 全选或者单选checkbox的值动态添加到div

    图片.png <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> < ...

  4. GDB中创建要素数据集

    转自 在geodatabase中创建要素集 //在数据集中创建要素 private void menuItem25_Click(object sender, System.EventArgs e) { ...

  5. 短网址ShortUrl的算法

    场景: 我们在新浪微博上公布网址的时候.微博会自己主动判别网址.并将其转换.比如:http://t.cn/hrYnr0. 为什么要这样做的,原因我想有这样几点: 1.微博限制字数为140字一条,那么假 ...

  6. [Angular] Learn How To Use ng-template Inputs

    For example, we have a modal component, it can config that using ng-template as a configurable templ ...

  7. java測试网络连接是否成功并设置超时时间

    /** * 获取RMI接口状态 * * @return "0":服务正常,"1": 连接报错,"2":连接超时 */ @Override p ...

  8. 修改SVN中文件的可执行属性

    博文来自下面路径,转载请注明原出处: http://bigwhite.blogbus.com/logs/74568031.html 修改SVN中文件的可执行属性 - [开源世界] Tag:开源世界 S ...

  9. POJ 3211 Washing Clothes 0-1背包

    题目大意: xxx很懒,但他有个漂亮又勤奋的女友 (尼玛能不能不刺激我,刚看到这题的时候发现自己的衣服没洗!!!) 可以帮他洗衣服. 洗衣服的时候要求不同的颜色的衣服不能同时洗.一人洗一件的话,问最短 ...

  10. js 省市二级联动

    <html> <head> <meta charset="UTF-8"> <title></title> </he ...