hdu_5805_NanoApe Loves Sequence(xjb搞)
题目链接:hdu_5805_NanoApe Loves Sequence
题意:
给你n个数,现在要删一个数,删每个数的概率是一样的,现在问你删一个值后的相邻数绝对值最大差的期望是多少,因为担心精度误差,让你答案乘n
题解:
先算出不删数的绝对值最大的差ma并记录位置,如果要删的数不是刚才求出来的位置,那么ans+=max(abs(a[i-1]-a[i+1],ma)。如果是,那么重新求一下最大值就行了,因为最多重求两次,所以总复杂度还是O(n)。
#include<cstdio>
#include<algorithm>
#define F(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
typedef long long ll;
const int N=1e5+;
ll a[N];
int t,n; ll getnew()
{
ll an=;
F(i,,n)an=max(an,abs(a[i]-a[i-]));
return an;
}
int main(){ scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
F(i,,n)scanf("%I64d",a+i);
ll pos,ma=;
F(i,,n){
int tp=abs(a[i]-a[i-]);
if(tp>ma)ma=tp,pos=i;
}
ll ans=;
F(i,,n)
{
if(i==pos||i==pos-)
{
if(i==)
{
ll tp=a[i];
a[i]=a[i+];
ans+=getnew();
a[i]=tp;
}else
{
ll tp=a[i];
a[i]=a[i-];
ans+=getnew();
a[i]=tp;
}
}else
{
if(i==||i==n)ans+=ma;
else{
ans+=max(ma,abs(a[i+]-a[i-]));
}
} }
printf("%I64d\n",ans);
}
return ;
}
hdu_5805_NanoApe Loves Sequence(xjb搞)的更多相关文章
- Best Coder #86 1002 NanoApe Loves Sequence
NanoApe Loves Sequence Accepts: 531 Submissions: 2481 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- hdu-5806 NanoApe Loves Sequence Ⅱ(尺取法)
题目链接: NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/13107 ...
- 5806 NanoApe Loves Sequence Ⅱ(尺取法)
传送门 NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/131072 K ...
- 5805 NanoApe Loves Sequence(想法题)
传送门 NanoApe Loves Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/131072 K ( ...
- BC#86 1003NanoApe Loves Sequence Ⅱ[two-pointer]
NanoApe Loves Sequence Ⅱ Accepts: 374 Submissions: 946 Time Limit: 4000/2000 MS (Java/Others) Me ...
- hdu 5273 Dylans loves sequence
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5273 Dylans loves sequence Description Dylans is give ...
- hdu 5273 Dylans loves sequence 逆序数简单递推
Dylans loves sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...
- HDU 5806 NanoApe Loves Sequence Ⅱ (模拟)
NanoApe Loves Sequence Ⅱ 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5806 Description NanoApe, t ...
- HDU 5805 NanoApe Loves Sequence (模拟)
NanoApe Loves Sequence 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5805 Description NanoApe, the ...
随机推荐
- react学习笔记-01
1. HTML模板 Jsx是react的语法糖,最终会被编译成js语法.因此需要第三方库browser将jsx转换成js. 由于react 0.14版本之后,将react和react-dom拆分,所以 ...
- QTP脚本汇总比较有价值
1.Object Spy的Tips Hold the CTRL key to change the window focus or perform other mouse operations 2. ...
- sql 将某列转换成一个字符串 for xml path用法
declare @test table( name varchar(10)) insert into @test values('a') insert into @test values('b') i ...
- 《JavaScript高级程序设计》读书笔记 ---基本包装类型
为了便于操作基本类型值,ECMAScript 还提供了3 个特殊的引用类型:Boolean.Number 和String.这些类型与本章介绍的其他引用类型相似,但同时也具有与各自的基本类型相应的特殊行 ...
- VMWARE player 如何让 win2012 guest os 支持HYPER-V
在 vm player 下安装了 win2012 r2, 但是启用 hyper-v的时候,提示不支持, 这时候要修改 Open the file Location for this Virtual M ...
- python websocket学习使用
前言 今天看了一些资料,记录一下心得. websocket是html5引入的一个新特性,传统的web应用是通过http协议来提供支持,如果要实时同步传输数据,需要轮询,效率低下 websocket是类 ...
- kali Rolling安装之后的一些常用配置总结
添加普通用户 useradd -m -G sudo,video,audio,cdrom -s /bin/bash OKing把某个用户添加到组中: sudo usermod -a 用户名 -G 组名 ...
- VC学习笔记: 1. Window程序内部运行机制
0. 内容结构 API与SDK 窗口与句柄 消息与消息队列 WinMain函数 1. API与SDK 这里 API是指由Windows操作系统提供给应用程序的编程接口: Windows系统提供的API ...
- Node使用Mongoose操作MongoDB数据库——增删改查的实现
当初刚出社会时就规划了下自己的职业生涯:先成为一名优秀的前端工程师,再成为一名全栈工程师(精通前端开发.后台开发和客户端开发),最后成为一名优秀的系统架构师.转眼间已经工作快三年,是时候迈出关键性的一 ...
- kettle在linux启动spoon.sh报错
org.eclipse.swt.SWTError: No more handles [gtk_init_check() failed] at org.eclipse.swt.SWT.error ...