hdu 2993 MAX Average Problem(DP+斜率优化)

MAX Average Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4153    Accepted Submission(s): 1052


Problem Description
Consider a simple sequence which only contains positive integers as a1, a2 ... an, and a number k. Define ave(i,j) as the average value of the sub sequence ai ... aj, i<=j. Let’s calculate max(ave(i,j)), 1<=i<=j-k+1<=n.
 


 

Input
There multiple test cases in the input, each test case contains two lines.
The first line has two integers, N and k (k<=N<=10^5).
The second line has N integers, a1, a2 ... an. All numbers are ranged in [1, 2000].
 


 

Output
For every test case, output one single line contains a real number, which is mentioned in the description, accurate to 0.01.
 


 

Sample Input
  
10 6 6 4 2 10 3 8 5 9 4 1
 


 

Sample Output
  
6.50
 


 

Source
 


 

Recommend
chenrui
 


 

思路:斜率优化,第一道

 

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int mm=100009;
long long sum[mm];
typedef pair<int,int> P;
P poin[mm];
int n,m,pos;
bool cross(P a,P b,P c)///上凸
{
    long long x,y,xx,yy;
    x=b.first-a.first;y=b.second-a.second;
    xx=c.first-b.first;yy=c.second-b.second;
    return y*xx>yy*x;
}
int bser(int l,int r,P&now)
{  int mid;
    while(l<r)
    {
        mid=(l+r)/2;
        if(cross(poin[mid],poin[mid+1],now))r=mid;
        else l=mid+1;
    }
    return l;
}
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {   sum[0]=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&sum[i]);sum[i]+=sum[i-1];
        }
        pos=0;
        float ans=0.0;
        for(int i=m;i<=n;i++)
        {
            P r(i-m,sum[i-m]),now(i,sum[i]);
            while(pos>1&&cross(poin[pos-1],poin[pos],r))pos--;
            poin[++pos]=r;
            int opt=bser(1,pos,now);///二分找最低点
            ///int opt=pos;
            double mid=(double)(sum[i]-poin[opt].second)/double(i-poin[opt].first);///最大斜率
            if(mid>ans)ans=mid;
        }
        printf("%.2f\n",ans);
    }
}


 

 

内容概要:本文介绍了一个基于多传感器融合的定位系统设计方案,采用GPS、里程计和电子罗盘作为定位传感器,利用扩展卡尔曼滤波(EKF)算法对多源传感器数据进行融合处理,最终输出目标的滤波后位置信息,并提供了完整的Matlab代码实现。该方法有效提升了定位精度与稳定性,尤其适用于存在单一传感器误差或信号丢失的复杂环境,如自动驾驶、移动采用GPS、里程计和电子罗盘作为定位传感器,EKF作为多传感器的融合算法,最终输出目标的滤波位置(Matlab代码实现)机器人导航等领域。文中详细阐述了各传感器的数据建模方式、状态转移与观测方程构建,以及EKF算法的具体实现步骤,具有较强的工程实践价值。; 适合人群:具备一定Matlab编程基础,熟悉传感器原理和滤波算法的高校研究生、科研人员及从事自动驾驶、机器人导航等相关领域的工程技术人员。; 使用场景及目标:①学习和掌握多传感器融合的基本理论与实现方法;②应用于移动机器人、无人车、无人机等系统的高精度定位与导航开发;③作为EKF算法在实际工程中应用的教学案例或项目参考; 阅读建议:建议读者结合Matlab代码逐行理解算法实现过程,重点关注状态预测与观测更新模块的设计逻辑,可尝试引入真实传感器数据或仿真噪声环境以验证算法鲁棒性,并进一步拓展至UKF、PF等更高级滤波算法的研究与对比。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值