2017年上海金马五校程序设计竞赛(网上资格赛)H : DHU Club Festival
2017-05-29 15:09
441 查看
Problem H : DHU Club Festival
From: DHUOJ, 2017051002Submit (Out of Contest)
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 xx (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 33, 44 and 88,
you will get a mixture with a concentration of 55.
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=23+22=2.
Input
There are several test cases, each contains two lines.The first line is nn (1≤n≤100)(1≤n≤100), the
number of the drinks.
The second line contains nn positive
integers cici (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
Author: nature、
解题思路:题意是说给你n种饮料,每种都要一个concentrations值,你可以每次两瓶混合在一起,得到一种新的饮料,此饮料的concentrations为原饮料的平均值,现在你可以每次混合两种,或者两种以上。求最好得到的一种饮料的concentrations的最大值。
贪心思想,先排序,每次混合两种。
我的代码:#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
int a[200],i,j;
for(i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
int sum=0;
sum=a[0];
for(i=1;i<n;i++)
sum=(sum+a[i])/2;
cout<<sum<<endl;
}
}
相关文章推荐
- 2017年上海金马五校程序设计竞赛(网上资格赛) Problem H : DHU Club Festival 贪心
- 2017年上海金马五校程序设计竞赛(网上资格赛)Problem H : DHU Club Festival
- 2017年上海金马五校程序设计竞赛(网上资格赛)Problem H : DHU Club Festival
- 2017年上海金马五校程序设计竞赛(网上资格赛) B Coach(并查集)
- 2017年上海金马五校程序设计竞赛(网上资格赛)Problem J : Raising Bacteria
- 2017年上海金马五校程序设计竞赛(网上资格赛)J : Raising Bacteria
- 2017年上海金马五校程序设计竞赛(网上资格赛)Problem A : Corn's new language
- 2017年上海金马五校程序设计竞赛(网上资格赛)Problem B : Coach
- 2017年上海金马五校程序设计竞赛(网上资格赛)部分题目题解
- 2017年上海金马五校程序设计竞赛(网上资格赛)Problem A : Corn's new language
- 2017年上海金马五校程序设计竞赛(网上资格赛) Problem J : Raising Bacteria
- 2017年上海金马五校程序设计竞赛(网上资格赛)Problem B : Coach
- 2017年上海金马五校程序设计竞赛(网上资格赛)Problem A : Corn's new language
- 2017年上海金马五校程序设计竞赛(网上资格赛) A : Corn's new language(括号匹配+求深度)
- 2017年上海金马五校程序设计竞赛(网上资格赛)Problem E : A No-story Kingdom
- 2017年上海金马五校程序设计竞赛 I : Frog's Jumping 找规律
- 2017年上海金马五校程序设计竞赛:Problem I : Frog's Jumping
- 2017年上海金马五校程序设计竞赛:Problem B : Sailing
- 2017年上海金马五校程序设计竞赛 A : STEED Cards 暴力
- 华东交通大学2017年ACM“双基”程序设计竞赛 1008