题目链接: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搞)的更多相关文章

  1. Best Coder #86 1002 NanoApe Loves Sequence

    NanoApe Loves Sequence Accepts: 531 Submissions: 2481 Time Limit: 2000/1000 MS (Java/Others) Memory ...

  2. hdu-5806 NanoApe Loves Sequence Ⅱ(尺取法)

    题目链接: NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others)     Memory Limit: 262144/13107 ...

  3. 5806 NanoApe Loves Sequence Ⅱ(尺取法)

    传送门 NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K ...

  4. 5805 NanoApe Loves Sequence(想法题)

    传送门 NanoApe Loves Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/131072 K ( ...

  5. BC#86 1003NanoApe Loves Sequence Ⅱ[two-pointer]

    NanoApe Loves Sequence Ⅱ  Accepts: 374  Submissions: 946  Time Limit: 4000/2000 MS (Java/Others)  Me ...

  6. hdu 5273 Dylans loves sequence

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5273 Dylans loves sequence Description Dylans is give ...

  7. hdu 5273 Dylans loves sequence 逆序数简单递推

    Dylans loves sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...

  8. HDU 5806 NanoApe Loves Sequence Ⅱ (模拟)

    NanoApe Loves Sequence Ⅱ 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5806 Description NanoApe, t ...

  9. HDU 5805 NanoApe Loves Sequence (模拟)

    NanoApe Loves Sequence 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5805 Description NanoApe, the ...

随机推荐

  1. Mysql存储过程和函数

    Mysql存储过程和函数 基本概念: 创建存储过程和函数是指将经常使用的一组SQL语句的组合在一起,并将这些SQL语句当作一个整体存储在MySQL服务器中.例如,银行经常需要计算用户的利息.不同类别的 ...

  2. dom4j操作xml文档

    java Dom4j解析XML文件 标签(空格分隔):java进阶 xml文档: <?xml version="1.0" encoding="UTF-8" ...

  3. 回滚 rollback

    为了保证在应用程序.数据库或系统出现错误后,数据库能够被还原,以保证数据库的完整性,所以需要进行回滚. 回滚(rollback)就是在事务提交之前将数据库数据恢复到事务修改之前数据库数据状态. 回滚执 ...

  4. iOS开发工具箱

    工欲善其事 必先利其器 最新重新安装了MacBook Air和Mac Pro的系统,彻底解决了一编译就报硬盘空间不足的问题.平时开发中比较常用的工具都需一一安装. XCode:没什么好说的,外星人都知 ...

  5. 【MySQL】filesort.cc 源代码阅读笔记

    最近阅读了部分MySQL排序的代码,把心得记录一下. 参考代码 MySQL: 文件: filesort.cc 函数: filesort() 排序过程伪代码 function filesort(tabl ...

  6. UVa 11426

    首先我们了解一下欧拉函数phi[x],phi[x]表示的是不超过x且和x互素的整数个数 phi[x]=n*(1-1/p1)*(1-1/p2)....(1-1/pn); 计算欧拉函数的代码为 int e ...

  7. jquery远程班备忘

    基础第一课: 1. $(obj)获取的是一个集合,因此length最小是1, jquery,如果元素不存在,也不会报错,可通过$(obj).length<1就可以查看该元素是否存在. 2. at ...

  8. iOS开发app自动更新的实现

    #define kStoreAppId @“xxxxxxxxx” // (appid数字串) -(void)checkAppUpdate { NSDictionary *infoDict = [[NS ...

  9. SDCC 2016中国软件开发者大会十三大主题

    SDCC中国软件开发者嘉年华(Software Developer Carnival China),是由全球最大中文IT社区CSDN于2007年创办的软件技术领域顶级盛会,将如约于2016年11月18 ...

  10. JavaScript的DOM(文档对象)基础语法总结2

    1.getAttribute()方法,通过元素节点的属性名称获取属性的值. //语法 elementNode.getAttribute(name) //element(元素);Node(节点) //注 ...