BestCoder Round #86 1002 HDU 5805 ——NanoApe Loves Sequence
题意
给定一个数列,随机从该数列里删除一个数,求该数列的的相邻之间的绝对值的最大值的和。
思路
两个数列来分别维护i位前面的相邻的绝对值的最大以及i后面的最大,枚举每一个可能删除的数,然后分别从左右和要删除的这个空档里娶一个最大的值。
code:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>using namespace std;typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;const int INF=0x3fffffff;
const int inf=-INF;
const int N=100005;
const int M=2005;
const int mod=1000000007;
const double pi=acos(-1.0);#define cls(x,c) memset(x,c,sizeof(x))
#define cpy(x,a) memcpy(x,a,sizeof(a))
#define ft(i,s,n) for (int i=s;i<=n;i++)
#define frt(i,s,n) for (int i=s;i>=n;i--)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lrt rt<<1
#define rrt rt<<1|1
#define middle int m=(r+l)>>1
#define lowbit(x) (x&-x)
#define pii pair<int,int>
#define mk make_pair
#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)int read() {char ch;while (ch = getchar(), !isdigit(ch));int res = ch - '0';while (ch = getchar(), isdigit(ch))res = res * 10 + ch - '0';return res;
}
//++++++++++++密++++++++++++++封++++++++++++++++++++线ll v[N],s1[N],s2[N];
int main()
{int T=read();ft(ca,1,T){int n=read();memset(s1,0,sizeof(s1));memset(s2,0,sizeof(s2));ft(i,1,n){scanf("%I64d",v+i);if (i>1){ll tq=abs(v[i]-v[i-1]);s1[i]=max(s1[i-1],tq);}}frt(i,n,1){if (i<n){ll tq=abs(v[i]-v[i+1]);s2[i]=max(s2[i+1],tq);}}ll ans=s2[2]+s1[n-1];ft(i,2,n-1){ll tq=abs(v[i+1]-v[i-1]);tq=max(tq,s1[i-1]);tq=max(tq,s2[i+1]);ans+=tq;}printf("%I64d\n",ans);}
}
BestCoder Round #86 1002 HDU 5805 ——NanoApe Loves Sequence相关推荐
- BestCoder Round #86 1003 HDU 5806——NanoApe Loves Sequence Ⅱ
题意: 给定一个序列,问在这个序列里有多少区间第k的的数>=m 思路: 在比赛的时候是多想了,开始像区间第k大的问题,赛后想想实在是偏了. 正确的解法是枚举起点然后用尺取法维护一段区间,直到找到 ...
- 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II
题目传送门 1 /* 2 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 3 当然有可能两个数和超过p,那么an ...
- HDU 5804 BestCoder Round #86 Price List (水题)
Price List 题目链接: 点我打开链接 Source BestCoder Round #86 题意:有一个人去 n 间商店购物,在每家商店购买最多一件物品,也可以什么都不买.给你每家商店的物 ...
- 矩阵快速幂---BestCoder Round#8 1002
当要求递推数列的第n项且n很大时,怎么快速求得第n项呢? 可以用矩阵快速幂来加速计算. 我们可以用矩阵来表示数列递推公式 比如fibonacci数列 可以表示为 [f(n) f(n-1)] = [ ...
- BestCoder Round #86 HDU 5804,HDU 5805,HDU 5806,HDU 5807
第一题: HDU 5804 链接 0 - 商品总和之间的任意价格都可以取到 每次判断记录是否大于总和即可 代码: #include <cstdio> #include <iostre ...
- BestCoder Round #78 (div.2)_B_ CA Loves GCD
CA Loves GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) T ...
- hdu 5273 Dylans loves sequence 逆序数简单递推
Dylans loves sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...
- hdu 4932 BestCoder Round #4 1002
这题真是丧心病狂,引来今天的hack狂潮~ Miaomiao's Geometry Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- BestCoder Round #80 1002
HDU 5666 Segment 题意:给你条斜率为-1,常数项为q(q为质数)的直线,连接原点与直线上整数格点,问你在有多少个格点在形成的无数个三角形内,而不在线段上,结果对P取模. 思路:best ...
最新文章
- 我们离爱因斯坦想了解的“上帝的思想”,还有多远?
- .NET 获得指定XML配置文件内容
- 4.13 apache用户认证,跳转和访问日志
- 宝塔 面板 放行端口
- JavaScript--关于变量提升思考
- php生成超链接完整代码_PHP自动把网站自动添加超链接怎么写
- C++---之Arraylist
- 常用计算机名词解释,计算机常用名词解释
- 小小精彩的flash
- uniapp安卓app里拦截webview下载apk,显示下载进度
- 蓝牙耳机哪种通话效果最好?通话质量最好的蓝牙耳机盘点
- Tex, LaTex, pdflatex, xelatex, xetex等的区别和关系
- Go(Golang)_12_竞态
- Flume-----八种采集方案
- 最简单的共享列表服务器KissLists
- 深度学习跨层网络结构--特征融合
- 一篇解决:Ubuntu安装配置、软件、工具、快捷键
- W77E58在GPS远程定位的应用(源代码) .
- 用python的statamodels模块拟合VAR模型
- 麦肯锡报告翻译:《超越狂欢:区块链的商业战略价值是什么?》