NYOJ-1242-Interference Signal

    xiaoxiao2021-04-16  25

    时间限制: 2000 ms  |  内存限制: 65535 KB 难度: 1 描述

    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 题意就不翻译了,原谅我的懒; 很简单的一道水题,用尺取法做。

    #include <stdio.h>#include <algorithm>int main(){ using namespace std; int s[2005]; int n; scanf("%d",&n); int a,b; double max_s; while(n--) { scanf("%d%d",&a,&b); max_s = s[0] = 0; for(int i=1; i<=a; i++) { scanf("%d",&s[i]); s[i] += s[i-1]; } for(int i=0; i<=a-b;i++) { for(int j=i+b; j<=a; j++) { max_s = max(max_s , (s[j]-s[i])*1.0/(j-i)); } } printf("%d\n",(int)(max_s*1000));//这里必须转化成int类型,第一次没转化,取用%.0lf错了 } return 0;}

    转载请注明原文地址: https://ju.6miu.com/read-672543.html

    最新回复(0)