Intense Heat 来自菜鸡的记录

什么是前缀和

 前缀和其实可以把它理解为数学上的数列的前n项和(对于一个一维数组的前缀和)。
 我们定义对于一个数组a的前缀和数组s,s[i] = a[1]+a[2]+…+a[i].
 新建一个数组,数组中每一项sum[i[保存原来数A中[0.....i]的和;

代码:

    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i= 1;i<=n;i++)
    {
        b[i] = b[i-1] + a[i];
    }

上边就是求前缀和的代码片段。

题目的大意为:
一个长度为n的序列,求该序列的长度≥k的子区间中平均值最大的那个区间的平均值。

直接上代码

来自菜鸡的记录
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 5005
int a[N];
int b[N];
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i= 1;i<=n;i++)
    {
        b[i] = b[i-1] + a[i];
    }//求出前缀和数组
    double s = 0.0;
    double z = 0.0;
    for(int i = k;i<=n;i++)//枚举区间长度
    {
        for(int j=1;j+i<=n+1;j++)
        {
            z = (b[j+i-1] - b[j-1])*1.0/i;
            s = max(s,z);
        }
    }
    printf("%.15f",s);//注意题目的精度问题
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是程序代码: ```c #include <stdio.h> // 定义一个结构体来表示一个点 struct Point { float x; float y; float z; float intense; }; // 定义一个结构体来表示一个预测框 struct BoundingBox { float x_min; float y_min; float z_min; float x_max; float y_max; float z_max; }; // 将预选框内部的点的intense值设为0的函数 void zeroIntenseWithinBox(struct Point *pointCloud, int pointCount, struct BoundingBox box) { for (int i = 0; i < pointCount; i++) { struct Point point = pointCloud[i]; if (point.x >= box.x_min && point.x <= box.x_max && point.y >= box.y_min && point.y <= box.y_max && point.z >= box.z_min && point.z <= box.z_max) { point.intense = 0; pointCloud[i] = point; } } } int main() { // 假设这是一个点云文件,里面有10个点 struct Point pointCloud[10] = { { 0, 0, 0, 1 }, { 1, 1, 1, 2 }, { -1, -1, -1, 3 }, { 2, 2, 2, 4 }, { -2, -2, -2, 5 }, { 3, 3, 3, 6 }, { -3, -3, -3, 7 }, { 4, 4, 4, 8 }, { -4, -4, -4, 9 }, { 5, 5, 5, 10 } }; // 假设这是一个预测框 struct BoundingBox box = { -2, -2, -2, 2, 2, 2 }; // 调用zeroIntenseWithinBox函数将预选框内部的点的intense值设为0 zeroIntenseWithinBox(pointCloud, 10, box); // 打印修改后的点云文件 for (int i = 0; i < 10; i++) { struct Point point = pointCloud[i]; printf("%f %f %f %f\n", point.x, point.y, point.z, point.intense); } return 0; } ``` 这个程序会读入一个点云文件和一个预测框,然后将预测框内部的点的intense值设为0,最后输出修改后的点云文件。您需要将预测框和点云文件的具体参数替换到程序中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值