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 ...
随机推荐
- android studio的lib和jniLibs
在android studio 中添加jar和so时,将jar文件直接拷贝到 项目目录\app\libs下即可,将so文件按照平台分类目录放到 项目目录\app\src\main\jniLibs\平台 ...
- C#变量修饰符
访问修饰符 关键字包括:internal,public,protected和private,用于设置变量的访问级别. public 变量可以做为它所属的类型的一个字段,可以在任何地方访问它. i ...
- JAVA语法基础(课堂ppt问题总结)
一:运行源代码EnumTest.java,分析运行结果. 代码如下: public class EnumTest { public static void main(String[] args) { ...
- JZ2440串口打印字符作为调试
/* * 初始化UART0 * 57600,8N1,无流控 */ void uart0_init(void) { GPHCON |= 0xa0; // GPH2,GPH3用作TXD0,RXD0 GPH ...
- Windows下WordPress搭建博客过程
搭建环境:Win7 + XAMPP5.5 + wordpress4.5.1 官网下载安装包,解压,拷贝到网站根目录(D:\IT\XAMPP5.5\htdocs\),重命名为blog(随意) 创建数据库 ...
- magento数据查询
一.查询出所有的数据: 1.以mysql查询语句在magento里执行,以此来查询你所需要的语句! $read = Mage::getSingleton('core/resource')->ge ...
- JS面向对象基础1
根据之前看了面向对象相关的视频,按照自己的理解,整理出相关的笔记,以便自己的深入理解. 如果要判断两个数是否相等,将值乘以10或者100,转换成整数再进行比较 例如:a++与++a 短路运算符 ...
- c# propertyGrid下拉选项
实现下面效果的propertygrid属性下拉选择
- 屏幕坐标和世界坐标的转换+对象池技术(3D打地鼠小游戏)
游戏中可能经常会遇到需要某个物体跟着鼠标移动,然后又需要把物体放在某个鼠标指定的位置 实现方式 Camera.main.WorldToScreenPoint Camera.main.ScreenToW ...
- Infix expression 计算 without '(' and ')'
#include<iostream> #include<stack> #include<string> using namespace std; char comp ...