Nyoj 1242 Interference Signal (Henan province, the first ACM Program Design Competition)

Source: Internet
Author: User
Tags time limit
Topic 1242 topic Information running results Discussion area Interference SignalTime limit: Ms | Memory limit: 65535 KB Difficulty: 1 description

Dr.kong ' s laboratory monitor some interference signals. The interference signals can is digitized into a series of positive integers. May is, there is 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.

Dr.kong to calculate the maximum average strength, given the constraint. Enter 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
Output for each test case generate a single line containing a single integer this is the maximal average value. Do not perform rounding. Sample input

Sample output
65007333
Source eighth session of Henan Province Program design Contest uploader

Hnu_acm

Two notes one is an at least one is do not perform rounding.

#include <stdio.h>
#include <string.h>
int main ()
{
	int ncase,a[2005];
	scanf ("%d", &ncase);
	while (ncase--)
	{
		int n,m;
		Double sum,max=-0x3fffffff;
		memset (A,0,sizeof (a));
		scanf ("%d%d", &n,&m);
		for (int i=0;i<n;i++)
		scanf ("%d", &a[i]);
		for (int i=0;i+m<=n;i++)
		{for
			(int k=m;k<=n&&i+k<=n;k++)
			{
				sum=0;
				for (int j=0;j<k;j++)
				sum+=a[i+j];
				if (Sum/k>max)
				max=sum/k;
			}
		}
		printf ("%d\n", (int) (max*1000));
	}
	return 0;
}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.