2017年上海金马五校程序设计竞赛(网上资格赛)Problem H : DHU Club Festival

Problem H : DHU Club Festival


Time Limit:  1 s

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:  {c1,c2,,cn} {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  ci ci  (1ci100) (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

 

分析

可以考虑先将各个杯中的浓度排序,因为如果两个数相差太大,平均之后会将整体平均值拉低,而且如果大的数和小的数一起也会将整体平均值拉低,如果直接将全部混合,因为最终浓度取的是整数部分,全部融合平均值可能会偏低。所以考虑将浓度排序之后两两往后取平均值。

代码

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
    int n,a[110];
    while(~scanf("%d",&n))
    {
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        sort(a,a+n);//将浓度排序
        for(int i=1;i<n;i++)
        {
            a[i]=(a[i]+a[i-1])/2;//两两取平均值并存放到两个中较后的那个位置,以便于下一步操作
        }
        printf("%d\n",a[n-1]);//最终位置存的即为最大平均浓度
    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值