原题:
http://poj.org/problem?id=2709
//poj 2709 略水
//题意:商店有不同的元件,不同元件可以提供数量不同的的颜料种类,每种的容量为 50ml(没有灰色), 而3种不同的颜料可以混合成灰色,注意混合后的体积不会改变,
// 比如Vml的a,Vml的b,Vml的c混合变成灰色体积还是Vml
// 输入先给出一个n,表示对n种颜料的需求,最后一个整数是对灰色的需求(灰色可以从前面的n种颜料配出来),问最少需要多少个元件(元件的类别就是
// 可以提供正好 n种50ml不同颜色颜料的 元件)
//思路:把灰色的量每减1ml,对应加到n种颜料中 需求量最少 的三种颜料上面,直到灰色颜料==0,再查看n中颜良中最大的量是多少,它决定了我们需要多少个元件。
//可以for循环,也可以用队列...读了好久才明白题目在说什么.
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
while(n!=0)
{
priority_queue<int,vector<int>,greater<int> >q1;//优先队列,由小到大排序
for(int i=0;i<n;i++)
{
int a;
scanf("%d",&a);
q1.push(a);
}
int t;
scanf("%d",&t);
while(t>0) //每次减1ml灰色
{
int a=q1.top()+1;
q1.pop();
int b=q1.top()+1;
q1.pop();
int c=q1.top()+1;
q1.pop();
q1.push(a);
q1.push(b);
q1.push(c);
t--;
}
while(q1.size()>1)
{
q1.pop();
}
int num=q1.top()/50;
if(q1.top()%50){
num++;
}
printf("%d\n",num);
scanf("%d",&n);
}
return 0;
} //AC