//11077849 c00h00g 2709 Accepted 168K 0MS C++ 1799B 2012-12-04 19:56:58
//状态太差了,这道题目WA的原因很烂
//这道题目一定要1ml1ml的去混合
//样例:4 90 95 75 95 10 如果使用两个kit的话,则剩余的量为用2*50去剪
//剩下的为:10 5 25 5要拼出10,只需要将这四个数放入优先队列中去拼,一个5用完了,还有另一个5可用
//还要注意的一点是: 优先队列写上greater的话表示从小到大,这儿一开始也晕了
#include<stdio.h>
#include<stdlib.h>
#include<queue>
using namespace std;
int N;
int amount[15];
int mix;
int main(){
while(scanf("%d",&N)!=EOF&&N){
int Max=-1;
for(int i=1;i<=N;i++){
scanf("%d",&amount[i]);
if(Max<amount[i])
Max=amount[i];
}
scanf("%d",&mix);
int nf;
if(Max%50==0){
nf=Max/50;
}else{
nf=Max/50+1;
}
int i;
if(mix==0){
printf("%d\n",nf);
}
else{
priority_queue<int> q;
//由于mix也要修改所以也要保存一下
int tt=mix;
while((i=nf++)>=0){
mix=tt;
while(!q.empty())
q.pop();
int v=i*50;
//看看还剩下多少颜料
for(int j=1;j<=N;j++){
int tmpa=v-amount[j];
//直接这样修改amount导致错误,因为下次amount还要用到
//amount[j]=v-amount[j];
if(tmpa>0){
q.push(tmpa);
}
}
bool flag=false;
while(q.size()>=3){
int a=q.top();q.pop();
int b=q.top();q.pop();
int c=q.top();q.pop();
--a;--b;--c;--mix;
if(mix==0){
flag=true;
break;
}
if(a>0)
q.push(a);
if(b>0)
q.push(b);
if(c>0)
q.push(c);
}//while
if(flag)
break;
}//while
printf("%d\n",i);
}//else
}
return 0;
}
POJ 2709
最新推荐文章于 2017-10-10 16:27:21 发布