题目链接: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. php生成图片缩略图的类方法

    //php生成缩略图片的类 class ResizeImage{ public $type;//图片类型 public $width;//实际宽度 public $height;//实际高度 publ ...

  2. html5+css3 文章的展示demo

    index.html   页面的样式 <!DOCTYPE html><html lang="en"> <head> <title>l ...

  3. 【原创】Spring MVC项目搭建(使用Java配置)

    一.使用Intellij idea,新建maven项目,选择maven-archetype-webapp. 二.在src/main下新建文件夹,命名为java,并标注为source folder. 三 ...

  4. XPath相关笔记

    <?xml version="1.0" encoding="utf-8" ?> <employees>   <employee o ...

  5. 基于Debian系统配置Nginx环境的Node.js应用教程

    Node.js,是当前比较流行的能够动态的快速响应内容的JavaScript框架,在有些环境下比我们使用的PHP应用都能够提高效率.目 前,Node.js可以与我们常用的Nginx.Apache等服务 ...

  6. 网站生产app的一些网址

    1.http://www.staticgen.com/2.http://siteapp.baidu.com3.http://www.apicloud.com

  7. 2、创建File类对象

    既然是内置类,那么我们创建对象时自然要看它封装好的构造函数咯,由下图的4中构造函数我们可知有4种办法来创建File对象 具体代码如下 public class Demo { public static ...

  8. js--事件对象的理解2

    实例1:一串跟着鼠标飞舞的div <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "h ...

  9. 【LeetCode】2.Add Two Numbers

    首先想到的是走到其中一个链表的尽头,然后把剩余的链表中的值放入写的链表,返回,但是自己写的代码好长. struct ListNode* addTwoNumbers(struct ListNode* l ...

  10. POJ 2209 The King#贪心

    (- ̄▽ ̄)-*  水 //水题:潜力^e为正数(e为2时都可以)的儿子都可以去上战场了, //英文要看懂,exponent指数,不超过3的正数 #include<iostream> #i ...