Problem H : DHU Club Festival
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 (x≥2) (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 (1≤n≤100) (1≤n≤100), the number of the drinks.
The second line contains n n positive integers ci ci (1≤ci≤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
分析
代码
#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]);//最终位置存的即为最大平均浓度
}
}