模拟题,在合成灰色的时候,每次取当前剩余最多的三种颜色,各取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 = 0; for (int i = 0; i < color_num; i++) { scanf("%d", &color_vol[i]); max_vol = max(color_vol[i], max_vol); } scanf("%d", &gray_vol); ans = (max_vol + 49) / 50; } void produce_gray() { priority_queue<int> pq; for (int i = 0; i < color_num; i++) if (color_vol[i] != 0) { pq.push(color_vol[i]); color_vol[i] = 0; } while (pq.size() >= 3) { 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 = 0; while (!pq.empty()) { color_vol[i] = pq.top(); pq.pop(); i++; } } void work() { for (int i = 0; i < color_num; i++) color_vol[i] = ans * 50 - color_vol[i]; while (1) { produce_gray(); if (gray_vol <= 0) break; ans++; for (int i = 0; i < color_num; i++) color_vol[i] += 50; } printf("%d ", ans); } int main() { while (scanf("%d", &color_num), color_num) { input(); work(); } return 0; }