1 solutions

  • 0
    @ 2023-1-29 13:23:26
    #include<bits/stdc++.h>
    using namespace std;
    /*
    求从每个数开始连续m个数的和,打擂台求最大,
    再求平均。 
    */
    int a[110]; 
    int main()
    {
    	int n, m;
    	cin >> n >> m;
    	for(int i = 1; i <= n; i++){
    		cin >> a[i];
    	}
    	//求从每个数开始连续m个数的和,
    	//最多循环到倒数第m个数才能保证有m个数
    	int s;
    	int ma = 0;//最大的和
    	for(int i = 1; i <= n-m+1; i++){
    		//求连续m个数的和
    		s = 0;
    		for(int j = i; j <= i+m-1; j++){
    			s += a[j];
    		} 
    		if(s > ma) ma = s;
    	}
    	cout << fixed << setprecision(2) << 1.0 * ma / m; 
    	return 0;
    }
    
    

    Information

    ID
    505
    Time
    1000ms
    Memory
    64MiB
    Difficulty
    10
    Tags
    # Submissions
    7
    Accepted
    4
    Uploaded By