NYoj 1242 Interference Signal&&2015第九届河南省acm程序设计大赛G题

描述
Dr.Kong’s laboratory monitor some interference signals. The interference signals can be digitized into a series of positive integer. May be, there are N integers a1,a2,…,an.

Dr.Kong wants to know the average strength of a contiguous interference signal block. the block must contain at least M integers.

Please help Dr.Kong to calculate the maximum average strength, given the constraint.

输入
The input contains K test cases. Each test case specifies:
* Line 1: Two space-separated integers, N and M.
* Lines2~line N+1: ai (i=1,2,…,N)
1 ≤ K≤ 8, 5 ≤ N≤ 2000, 1 ≤ M ≤ N, 0 ≤ ai ≤9999
输出
For each test case generate a single line containing a single integer that is 1000 times the maximal average value. Do not perform rounding.
样例输入
2
10 6
6
4
2
10
3
8
5
9
4
1
5 2
10
3
8
5
9
样例输出
6500
7333

题目难度比较小,只不过是英文,所以让人不敢下手,根据这两天做15,16年省赛题目,发现,水题一般都在英文题中,所以针对这次的acm程序设计比赛,我决定让我们组发下来试题之后,先翻译一下英文题目,然后每个人针对性的选自己会的题目进行解题。英文水题一定要做了。
这个题目的大概意思就是说,给一串数字,把其中平均值最高的那一段连续的数字找出来。这段数字的长度,也就是个数,必须大于给定的一个数M,我就很暴利的去做了,把所有段数字都枚举出来了。最后长度大于M的并且大与前一个均值最高的数字,那就保存下来。就这样,最后还有就是,数据不允许四舍五入,直接取整,所以,我又用了向下取整函数floor ,需要加载的头文件是math.h,顺便说一下向上取整函数ceil函数。嗯,整个题目就是这样了。当然我觉得是可以优化的,就是说,只找M长度以上的串数字均值,这样会省些功夫。谁知道,不用这样优化就可以过,那就这样了。。。。。


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    int a, b, i, j, k, l;
    int n, m;
    scanf("%d",&k);

    for(i=0;i<k;i++)
    {
        double  maxn=0;
        int sum=0;
        scanf("%d %d",&n,&m);
        int a[n];

        for(j=0;j<n;j++)
        scanf("%d",&a[j]);

        for(j=0;j<n;j++)
        {


            sum=0;
                for(l=j;l<n;l++)
            {
                sum=sum+a[l];

                double qwer=sum*1.0/(l-j+1);
                if(qwer>maxn&&m<=l-j+1)
                {
                    maxn=qwer;
                }


            }

        }
        printf("%.0f\n",floor(maxn*1000));

    }

    return 0;
 }         

希望等几天的acm程序设计竞赛,我们小组不会爆零。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
x1y2 x2y3 x3y1-x1y3-x2y1-x3y2 是计算三角形面积的公式中的一部分。 在这个公式中,x1、x2、x3分别表示三角形的三个顶点的x坐标,y1、y2、y3分别表示三角形的三个顶点的y坐标。通过计算这个表达式的值,可以得到三角形的面积。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [TetraCluster:使用并行Java 2库的Java并行程序。 该程序在群集并行计算机上运行,​​以从给定的点集中找到...](https://download.csdn.net/download/weixin_42171208/18283141)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [线性代数有个,求正交变换x=Qy,化二次型f(x1,x2,x3)=8x1x2+8x1x3+8x2x3为标准型求出特征值](https://blog.csdn.net/weixin_39956182/article/details/115882118)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [nyoj-67-三角形面积(S=(1/2)*(x1y2+x2y3+x3y1-x1y3-x2y1-x3y2))](https://blog.csdn.net/weixin_30492601/article/details/99541033)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值