poj2709

时间:2022-03-22 11:30:59

模拟题,在合成灰色的时候,每次取当前剩余最多的三种颜色,各取1mL合成。然后重新看剩余最多的是哪三个。

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
using namespace std; #define MAX_COLOR_NUM 20 int color_num;
int gray_vol;
int color_vol[MAX_COLOR_NUM];
int ans; void input()
{
int max_vol = ;
for (int i = ; i < color_num; i++)
{
scanf("%d", &color_vol[i]);
max_vol = max(color_vol[i], max_vol);
}
scanf("%d", &gray_vol);
ans = (max_vol + ) / ;
} void produce_gray()
{
priority_queue<int> pq;
for (int i = ; i < color_num; i++)
if (color_vol[i] != )
{
pq.push(color_vol[i]);
color_vol[i] = ;
}
while (pq.size() >= )
{
int a = pq.top();
pq.pop();
int b = pq.top();
pq.pop();
int c = pq.top();
pq.pop();
a--;
b--;
c--;
gray_vol--;
if (a)
pq.push(a);
if (b)
pq.push(b);
if (c)
pq.push(c);
}
int i = ;
while (!pq.empty())
{
color_vol[i] = pq.top();
pq.pop();
i++;
}
} void work()
{
for (int i = ; i < color_num; i++)
color_vol[i] = ans * - color_vol[i];
while ()
{
produce_gray();
if (gray_vol <= )
break;
ans++;
for (int i = ; i < color_num; i++)
color_vol[i] += ;
}
printf("%d\n", ans);
} int main()
{
while (scanf("%d", &color_num), color_num)
{
input();
work();
}
return ;
}