DHU Club Festival


<button class="btn btn&#45;default" id="submit&#95;open&#95;top" type="button"> Submit</button>
&amp;lt;a type=&quot;button&quot; class=&quot;btn btn-warning&quot; href=&quot;/solution/submit.html?problemId=5272&quot;&amp;gt;Submit&amp;lt;/a&amp;gt;
<center> Time Limit: 1 s </center>

Description

During the past DHU Club Festival, XiaoTang got many bottles of drinks, but each was of a different taste. And they were not of the same concentration.

Sometimes it's just that confusing with too many choices. XiaoTang decided to mix all of them up to create an extreme unique taste. Please help him. Following is the rule of mixing.

Given the concentrations of each drink: {c 1 ,c 2 ,,c n } {c1,c2,⋯,cn}, each time you can take x x (x2) (x≥2) bottles of drinks and mix them up. It is guaranteed that after your mixing, the concentration become the average number. For example, if you choose three drinks with concentrations of 3 3, 4 4 and 8 8, you will get a mixture with a concentration of 5 5. Repeat mixing until there is only one bottle drink left and your aim is to make the final concentration maximal.

Hint: In this problem, we use integer division, eg: 3+22 =2 3+22=2.

 

Input

There are several test cases, each contains two lines.

The first line is n n (1n100) (1≤n≤100), the number of the drinks.

The second line contains n n positive integers c i  ci (1c i 100) (1≤ci≤100), the concentration of each drink.

 

Output

For each test case, output the final concentration in a line.

 

Sample Input

2
2 3
1
1

 

Sample Output

2
1

 


Author: nature


思路:

n杯酒,每次都可以把若干杯匀到一起后再分摊,且会损失小数点后的精度。比如3,4平分之后变成了3,3,损失了1。

问,最多能每个杯子匀到多少。也就是使他们的损失最小。

本来以为是dp,但是仔细观察会发现其实是个数论问题。

当两个杯子匀的时候,分子为1则损失,分子为2就不会损失。

三个杯子的时候,分子为1、2会损失,分子为3不会损失。

四个杯子,分子为1、2、3会损失,分子为4不会损失

         .......

也就是说,当两个杯子的匀的时候,最多会损失1,而当1个以上匀的时候,最少为1,因此肯定每次两个两个的匀会损失的最小。所以只需每次找最小的两个匀,再把均匀后的那个加进去继续和别的匀。有点类似于Huffman树的思想。


代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<stack>
using namespace std;
 
int c[105];
 
int main()  
{  
    int n;  
    while(~scanf("%d",&n))  
    {  
        for(int i=1;i<=n;i++){
            scanf("%d",&c[i]);
        } 
        int sum=0;
        sort(c+1,c+n+1);
        int cnt=c[1];
        for(int i=2;i<=n;i++){
            cnt= (cnt+c[i])/2;
        }
        cout<<cnt<<endl;
    }  
    return 0;  
}