Best Coder #86 1002 NanoApe Loves Sequence
NanoApe Loves Sequence
NanoApe, the Retired Dog, has returned back to prepare for the National Higher Education Entrance Examination!
In math class, NanoApe picked up sequences once again. He wrote down a sequence with nnn numbers on the paper and then randomly deleted a number in the sequence. After that, he calculated the maximum absolute value of the difference of each two adjacent remained numbers, denoted as FFF.
Now he wants to know the expected value of FFF, if he deleted each number with equal probability.
The first line of the input contains an integer TTT, denoting the number of test cases.
In each test case, the first line of the input contains an integer nnn, denoting the length of the original sequence.
The second line of the input contains nnn integers A1,A2,...,AnA_1, A_2, ..., A_nA1,A2,...,An, denoting the elements of the sequence.
1≤T≤10, 3≤n≤100000, 1≤Ai≤1091 \le T \le 10,~3 \le n \le 100000,~1 \le A_i \le 10^91≤T≤10, 3≤n≤100000, 1≤Ai≤109
For each test case, print a line with one integer, denoting the answer.
In order to prevent using float number, you should print the answer multiplied by nnn.
1
4
1 2 3 4
6
/*第二次来水BC,暑假最后一场了,这次收获不错,水出两题,虽然第二题不知道什么是线段树,但是还是按照自己想法搞出来了,加油*/
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string.h>
#define N 100010
#define M 100000
using namespace std;
long long n, dp[N],pd[N],a[N], tep;
long long Max(long long a,long long b,long long c)
{
long long d=max(a,b);
long long e=max(b,c);
return max(d,e);
}
int main()
{
//freopen("in.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--)
{
memset(dp,,sizeof(dp));
memset(pd,,sizeof(pd));
vector <long long > v;
v.clear();
v.push_back();
scanf("%lld",&n);
for(int i = ; i <= n; i++)
{ scanf("%lld",&tep);
v.push_back(tep);
}
v.push_back();
dp[]=;
for(int i = ; i <= n;i++)
if(abs(v[i] - v[i - ])>dp[i-])
{
dp[i]=abs(v[i] - v[i-]);
}
else
dp[i] = dp[i - ]; reverse(v.begin(), v.end());
pd[]=;
for(int i = ; i <= n; i++)
if(abs(v[i] - v[i-]) > pd[i-])
pd[i] = abs(v[i] - v[i-]);
else
pd[i] = pd[i - ];
reverse(v.begin(), v.end());
long long s = ;
for(int i=;i<=n;i++)
{
if(i==)
s+=pd[n-];
else if(i==n)
s+=dp[n-];
else
s+=Max(dp[i-],abs(v[i+] - v[i-]),pd[n-i]);
}
printf("%lld\n",s);
}
return ;
}
Best Coder #86 1002 NanoApe Loves Sequence的更多相关文章
- 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 ( ...
- 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 ...
- NanoApe Loves Sequence Ⅱ(尺取法)
题目链接:NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/131072 ...
- hdu-5806 NanoApe Loves Sequence Ⅱ(尺取法)
题目链接: NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/13107 ...
- hdu-5805 NanoApe Loves Sequence(线段树+概率期望)
题目链接: NanoApe Loves Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/131072 ...
- HDU5806 NanoApe Loves Sequence Ⅱ
NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/131072 K (Ja ...
- Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) (C++,Java)
Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) Hdu 5806 题意:给出一个数组,求区间第k大的数大于等于m的区间个数 #include<queue> # ...
随机推荐
- multimap 和priority_queue详解
上一期是关于STL和并查集结合的例题,也附了STL中部分容器的使用摘要,由于是从网上东拼西凑的,感觉有的关键点还是没解释清楚,现在从其中摘出两个容器,用例题对它们的用法进行进一步解释. 以下是例题的介 ...
- tomcat部署项目的一点心得
打包方式 eclipse 右键项目Export 选择WAR file 在选择将打包好的war 包存放的位置 放到tomcat中运行 : 首先将war包fang放到解压的tomcat中的weba ...
- 第6章 Overlapped I/O, 在你身后变戏法 ---Win32 文件操作函数 -2
Win32 之中有三个基本的函数用来执行 I/O,它们是: i CreateFile() i ReadFile() i WriteFile() 没有另外 ...
- Running Spark on YARN
Running Spark on YARN 对 YARN (Hadoop NextGen) 的支持是从Spark-0.6.0开始的,后续的版本也一直持续在改进. Launching Spark on ...
- Vuforia开发完全指南(四)--- Image Target
Vuforia开发完全指南---Image Target,简单方便的AR图像识别 概述 在Vuforia提供的SDK中,最简单.也是最常见的AR功能就是Image Target---图像识别.你只需提 ...
- 实现径向变换用于样本增强《Training Neural Networks with Very Little Data-A Draft》
背景: 做大规模机器学习算法,特别是神经网络最怕什么--没有数据!!没有数据意味着,机器学不会,人工不智能!通常使用样本增强来扩充数据一直都是解决这个问题的一个好方法. 最近的一篇论文<Trai ...
- yii2-swiftmailer入门
1. 安装 用yii 2.0框架,默认会有这个扩展 composer require --prefer-dist yiisoft/yii2-swiftmailer 修改composer.json,re ...
- Java面向对象 线程技术 -- 下篇
Java面向对象 线程技术 -- 下篇 知识概要: (1)线程间的通信 生产者 - 消费者 (2)生产者消费者案例优化 (3)守护线程 (4)停止线 ...
- python 输出语句的写法
总结: 1.类似于C语言的格式化输出,先写转换符,再写待转换的对象. 2.与C语言不同的是,转换符和待转换的对象之间,不能用逗号分隔. #!/usr/bin/env python #print dig ...
- 浅谈oracle树状结构层级查询测试数据
浅谈oracle树状结构层级查询 oracle树状结构查询即层次递归查询,是sql语句经常用到的,在实际开发中组织结构实现及其层次化实现功能也是经常遇到的,虽然我是一个java程序开发者,我一直觉得只 ...