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 ...
随机推荐
- 大型网站技术架构 核心原理与案例分析 pdf
需要的小伙伴拿去,哈哈.百度云链接:https://pan.baidu.com/s/1hsuiM3q
- win10系统 L2TP连接尝试失败:ERROR因为安全层在初始化与远程计算机的协商时遇到了一个处理错误
1 确保IPsec Policy Agent服务已启动 2 确保路由和远程访问(Routing and Remote Access)和远程访问连接管理器服务(Remote Access Connect ...
- 【转】cookie和session的区别
原作者:施杨(施杨's Think out)出处:http://shiyangxt.cnblogs.com ************** 本文版权归原作者和博客园共有,欢迎转载,转载请保留该申明 ** ...
- Simple python reverse shell
import base64,sys; import socket,struct s=socket.socket(2,socket.SOCK_STREAM) s.connect(('Attack's I ...
- ajax成功案例
$.ajax({ type:"post", url:"<%=basePath%>getAllVersion", dataType:"jso ...
- 使用JavaScript进行数组去重——一种高效的算法
最近比较忙,没时间更新博客,等忙完这阵子会整理一篇使用AngularJS构建一个中型的单页面应用(SPA)的文章,尽情期待!先占个坑. 数组去重的算法有很多种,以下是一种. 思路如下: 定义一个空的对 ...
- Django中Admin样式定制
Django自带的admin在展示数据是样式有点单一,我们可以自己定义数据的展示样式. 一.自定义数据展示样式 1.后台查询书记列表时,同时列出出版社和出版时间: admin.py文件 from dj ...
- ElasticSearch(5)-Mapping
一.Mapping概述 映射 为了能够把日期字段处理成日期,把数字字段处理成数字,把字符串字段处理成全文本(Full-text)或精确的字符串值,Elasticsearch需要知道每个字段里面都包含了 ...
- SecureCRT 7.3.4破解版(含注册机)
不用说你肯定知道SecureCRT用途是什么,这个号称最好用的ssh连接工具却不是免费的,所以找了很久才找到最新版本的SecureCRT 7.3.4破解版,其实只要是SecureCRT 7.3.x版本 ...
- Openjudge-计算概论(A)-第二个重复出现的数
描述: 给定一个正整数数组(元素的值都大于零),输出数组中第二个重复出现的正整数,如果没有,则输出字符串"NOT EXIST". 输入第一行为整数m,表示有m组数据.其后每组数据分 ...