2017年上海金马五校程序设计竞赛(网上资格赛) 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  (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

 


这个题,呵呵,我是蒙的,因为不知道要拿多少瓶酒来调,这就纠结了,差点跪了,后来举例子发现,每次拿两瓶酒的时候是最优的,于是乎抱着揣测的心态我就写了个贪心。

然后已经做好百分百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);
		}
	}
}







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_我走路带风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值