ZOJ2091(Mean of Subsequence)

Mean of Subsequence

Time Limit: 1 Second      Memory Limit: 32768 KB

Given N numbers in a line, we can determine a continuous subsequence by giving its start position and its length.

PMH and Roy played a game the other day. Roy gives the start position first, then PMH gives the length. Roy wants the mean of the subsequence as large as possible, while PMH wants it as small as possible.

You are to calculate the best result Roy can get, assuming PMH is very clever.


Input

There are multiple testcases.

Each testcase begins with a line containing N only.

The following line contains N numbers, separated by spaces.


Output

For each testcase, you are to print the best mean of subsequece Roy can get, precise to 6 digit after decimal point.


Sample Input

10
2 10 4 6 5 10 10 2 3 2


Sample Output

5.777778

 

 

/*
    2009-05-10 18:35:22 Accepted  2091 C++ 80 216 
             -- by Xredman
*/
 
#include 
<stdio.h>

int str[10000];

int main()
{
    
float ans, sum;
    
int n, m, i;
    
    
while(scanf("%d"&n) != EOF)
    
{
        
if(n == 0)
        
{
            putchar(
'\n');
            
continue;
        }

        
        
///////第一段程序开始//////////
        /*ans = 0;
        for(i = 0; i < n; i++)
        {
            scanf("%d", str + i);
            ans += str[i];
        }
        
        sum = ans;
        ans /= n;
        m = n;
*/

        
//////////第一段程序结束///////////////// 
        
        
//////////////第二段程序开始/////////////////////

        sum = 0;
        
for(i = 0; i < n; i++)
        
{
            scanf(
"%d", str + i);
            sum 
+= str[i];
        }

        
        ans 
= sum;
        ans 
= sum / n;
        m 
= n;
        
        
////////////////////第二段程序结束//////////////////
        
        
////////////////////////////////////////////////

        //                  Warning!!!                //
        
//         在自己学校OJ用第二段程序始终会错误 //
        
//         在ZOJ上没有这种现象,绝对无语      //
        //////////////////////////////////////////////// 
        
        
for(i = 0; i < n - 1; i++)
        
{
            sum 
-= str[i];
            m
--;
            
if(sum / m >= ans)
                ans 
= sum / m;
        }

        printf(
"%.6f\n",ans);
    }

    
return 0;
}

posted on 2009-05-10 18:44  Xredman  阅读(245)  评论(0编辑  收藏  举报

导航