hdu NanoApe Loves Sequence
来源:互联网 发布:虚拟币场外交易源码 编辑:程序博客网 时间:2024/06/05 06:47
NanoApe Loves Sequence
Accepts: 505
Submissions: 1646
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 262144/131072 K (Java/Others)
6
求删除每个数后的序列最大差值的和
记录第一 第二 第三大的和,每次删除点时删除掉两个差值,新加入一个差值 第一个的最后一个数只删除一个差值
/************************************************┆ ┏┓ ┏┓ ┆┆┏┛┻━━━┛┻┓ ┆┆┃ ┃ ┆┆┃ ━ ┃ ┆┆┃ ┳┛ ┗┳ ┃ ┆┆┃ ┃ ┆┆┃ ┻ ┃ ┆┆┗━┓ ┏━┛ ┆┆ ┃ ┃ ┆ ┆ ┃ ┗━━━┓ ┆┆ ┃ AC代马 ┣┓┆┆ ┃ ┏┛┆┆ ┗┓┓┏━┳┓┏┛ ┆┆ ┃┫┫ ┃┫┫ ┆┆ ┗┻┛ ┗┻┛ ┆************************************************ */#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<vector>#include<algorithm>#include<iostream>#include<queue>#include<map>#define ll long longusing namespace std;int a[100010],Max[100010];int Abs(int i){ return i>0?i:(-i);}bool cmp(int i,int j){ return i>j;}int main(){ int t; scanf("%d",&t); while(t--) { memset(Max,-1,sizeof(Max)); int n; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",&a[i]); for(int i=0;i<n-1;i++) Max[i]=Abs(a[i]-a[i+1]); sort(Max,Max+n-1,cmp); ll ans=0; for(int i=0;i<n;i++) { if(i==0) { int num=Abs(a[1]-a[0]); if(num==Max[0]) { ans+=Max[1]; } else ans+=Max[0]; } else if(i==n-1) { int num=Abs(a[n-1]-a[n-2]); if(num==Max[0]) { ans+=Max[1]; } else ans+=Max[0]; } else { int num1=Abs(a[i]-a[i-1]); int num2=Abs(a[i]-a[i+1]); int num3=Abs(a[i+1]-a[i-1]); if(num1==Max[0]&&num2==Max[1]) { ans+=max(num3,Max[2]); } else if(num1==Max[1]&&num2==Max[0]) { ans+=max(num3,Max[2]); } else if(num1==Max[0]) { ans+=max(num3,Max[1]); } else if(num2==Max[0]) { ans+=max(num3,Max[1]); } else ans+=max(num3,Max[0]); } } printf("%lld\n",ans); }}
0 0
- hdu NanoApe Loves Sequence
- hdu NanoApe Loves Sequence
- hdu NanoApe Loves Sequence Ⅱ
- HDU 5805 NanoApe Loves Sequence
- HDU 5805:NanoApe Loves Sequence
- hdu 5805 NanoApe Loves Sequence
- HDU 5805 NanoApe Loves Sequence
- HDU 5805 NanoApe Loves Sequence
- HDU 5805 NanoApe Loves Sequence
- HDU 5805 - NanoApe Loves Sequence
- HDU 5805 NanoApe Loves Sequence
- HDU 5805 NanoApe Loves Sequence
- HDU 5806 NanoApe Loves Sequence
- HDU 5805 NanoApe Loves Sequence [Ad Hoc]
- Hdu 5805 NanoApe Loves Sequence【思维题】
- hdu 5086 NanoApe Loves Sequence 【二分查找】
- hdu 5806 NanoApe Loves Sequence Ⅱ
- HDU 5806 NanoApe Loves Sequence Ⅱ
- poj2299Ultra-QuickSort(归并求逆序数)
- 「Deep Learning」FCN - Fully Convolutional Networks
- (HDU 3032) Nim or not Nim(SG函数、博弈)
- 【leetcode】198. House Robber
- 数据结构学习笔记(十)哈希表(散列表)
- hdu NanoApe Loves Sequence
- sql语句那些事儿—mysql 又见存储过程
- poj 1321 棋盘问题
- java面试题集
- mnist_train_test.prototxt代码解析
- 你的linux机器上 grep xxx -rl ./ 会递归吗?
- 常见排序的最好,平均以及最坏时间复杂度
- Xcode创建的默认iOS OpenGL ES 2.0 project代码分析
- hdu NanoApe Loves Sequence Ⅱ