zoukankan      html  css  js  c++  java
  • NYOJ 1242 Interference Signal

    Interference Signal

     
     
    描述

    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

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 
     6 int a[2005];
     7 
     8 int main()
     9 {
    10     int k,n,m;
    11     scanf("%d",&k);
    12     while(k--)
    13     {
    14         scanf("%d%d",&n,&m);
    15         double aver=0.0;
    16         memset(a,0,sizeof(a));
    17         for(int i=1;i<=n;i++)
    18         {
    19             scanf("%d",&a[i]);
    20             a[i]+=a[i-1];
    21         }
    22         for(int i=1;i<=n;i++)
    23             for(int j=i+m-1;j<=n;j++)
    24             {
    25                 double tmp=(a[j]-a[i-1])*1.0/(j-i+1);
    26                 aver=max(aver,tmp);
    27             }
    28         int ans=(int)(aver*1000);
    29         printf("%d
    ",ans);
    30     }
    31     return 0;
    32 }


  • 相关阅读:
    python虚拟环境--virtualenv
    求导法则和高阶导数
    restful规范
    python协程--yield和yield from
    打印质数
    更改docker的存储位置
    同台ECS安装多个mysql
    jenkins + gitlab + harbor + k8s 部署项目
    jenkins 配置maven
    gitlab + jenkins 持续集成
  • 原文地址:https://www.cnblogs.com/homura/p/4895281.html
Copyright © 2011-2022 走看看