DHUOJ 2017051002 - DHU Club Festival(数论)

DHU Club Festival



<a type="button" class="btn btn-warning" href="/solution/submit.html?problemId=5272">Submit</a>

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: {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;  
}  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值