模拟题,在合成灰色的时候,每次取当前剩余最多的三种颜色,各取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 ;
}

poj2709的更多相关文章

  1. poj2709 贪心基础

    D - 贪心 基础 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     64bi ...

  2. 【poj2709】Painter--贪心

    Painter Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5621   Accepted: 3228 Descripti ...

  3. POJ2709 染料贪心

    题意:       要搭配出来n种颜料,每种颜料要用mi升,除了这n种颜色还有一个合成灰色的毫升数,灰色是由三种不同的颜色合成的,三种m m m 的不同颜色能合成m升灰色,然后问你满足要求至少要多少盒 ...

随机推荐

  1. css3新增的伪类和伪元素

    E:target事件属性可返回事件的目标节点(触发该事件的节点),如生成事件的元素.文档或窗口 E:disabled表示不可点击的表单控件 E:enabled表示可点击的表单控件 E:checked表 ...

  2. Java并发编程之深入理解线程池原理及实现

    Java线程池在实际的应用开发中十分广泛.虽然Java1.5之后在JUC包中提供了内置线程池可以拿来就用,但是这之前仍有许多老的应用和系统是需要程序员自己开发的.因此,基于线程池的需求背景.技术要求了 ...

  3. 微信小程序初窥-环境搭建

    关于微信小程序的背景知识,在此不做阐述,可以自行搜索了解.本文将介绍微信小程序的账号的注册,IDE的下载,创建一个实例小程序. 1.注册小程序 前去链接:https://mp.weixin.qq.co ...

  4. mininet invalid literal for int() with base 10: 'cpu.cfs_period_us:'

    问题产生原因:内核编译时没有加入 CONFIG_CFS_BANDWIDTH 选项 http://www.haifux.org/lectures/299/netLec7.pdf https://mail ...

  5. 使用doxygen静态分析开源代码

    doxygen是一款生成开源代码说明文件的工具,因为不需要编译源码,用作代码的分析也十分方便. 一.安装 sudo apt-get install graphviz sudo apt-get inst ...

  6. HGOI20180831 NOIP2018模拟

    input1: 4 4 4 4 4 3 2 4 5 4 5 5 5 1 7 3 2 output1: Yes Yes Yes No 好的吧数学题QwQ考场上没人做出来qwq 就是判断两个矩形能否互相放 ...

  7. 【CF1077F2】Pictures with Kittens 单调队列+dp

    题目大意:给定一个长度为 N 的序列,点有点权,从序列中选出恰好 X 个数,并且保证任意连续的 K 个数中均有一个被选中,求选出的点权最大是多少. 题解:此题可以作为 烽火传递+ 来处理,只不过在烽火 ...

  8. Linux掉电处理

    在嵌入式设备中,掉电处理一直是一项比较麻烦的工作,在具有Linux系统的设备中,系统的种种数据的处理更是增加掉电处理的难度.现在做以下几点总结,再遇到类似问题可以做个参考. 1,系统启动的处理 在系统 ...

  9. Codeforces 906 D. Power Tower

    http://codeforces.com/contest/906/problem/D 欧拉降幂 #include<cstdio> #include<iostream> usi ...

  10. dp的进阶 (一)

    熟练掌握dp的定义方法. ①四维dp的转移,生命值转移时候需要注意的 ②集合的定义,判断二进制内部是否有环 ③很难想到的背包问题 ④博弈类型的dp ⑤排列组合类型dp ⑥01背包的变种(01背包+完全 ...