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} , each time you can take x (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 , 4 and 8 , you will get a mixture with a concentration of 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 .
Input
There are several test cases, each contains two lines.
The first line is n (1≤n≤100) , the number of the drinks.
The second line contains n positive integers ci (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
这个题,呵呵,我是蒙的,因为不知道要拿多少瓶酒来调,这就纠结了,差点跪了,后来举例子发现,每次拿两瓶酒的时候是最优的,于是乎抱着揣测的心态我就写了个贪心。
然后已经做好百分百WA 的准备了,但是它A了。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
using namespace std;
int X[100];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=0;i<n;i++)
{
scanf("%d",&X[i]);
}
sort(X,X+n);
if(n==1) printf("%d\n",X[0]);
else
{
int max=(X[0]+X[1])/2;
for(int i=2;i<n;i++)
{
max=(max+X[i])/2;
}
printf("%d\n",max);
}
}
}