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

    vue适合移动端的项目,而angular更适合运用于Pc端的项目.

  2. final 评论 II

    第二次评论内容: 1.Nice!小组的约跑app: 项目内容足够丰富,在展示时也很好的体现了app的功能,可以满足所提出的需求.在展示的过程中表述所占比例较小,希望能够以更多的讲述过程完善用户理解的功 ...

  3. MySQL基础(一):基本操作

    一.下载安装及连接 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下公司.MySQL 最流行的关系型数据库管理系统,在 WEB 应用方面MySQL是 ...

  4. js写插件教程深入

    原文地址:https://github.com/lianxiaozhuang/blog 转载请注明出处 js 写插件教程深入 1.介绍具有安全作用域的构造函数 function Fn(name){ t ...

  5. javascript面向对象系列第五篇——拖拽的实现

    前面的话 在之前的博客中,拖拽的实现使用了面向过程的写法.本文将以面向对象的写法来实现拖拽 写法 <style> .test{height: 50px;width: 50px;backgr ...

  6. 【设计模式】—— 模板方法Template

    前言:[模式总览]——————————by xingoo 模式意图 定义一个类的框架,当它有不同的类时,再具体实现. 比如,我们设计一个跨系统的客户端软件,Windows需要一套展现类,Linux需要 ...

  7. CentOS系统下安装 LNAM环境

    系统需求: CentOS/RHEL/Fedora/Debian/Ubuntu/Raspbian Linux系统 需要3GB以上硬盘剩余空间 128M以上内存,Xen的需要有SWAP,OpenVZ的另外 ...

  8. C++中 0 与 NULL 与 nullptr之间的关系,nullptr_t 的实现

    C++中 0 与 NULL 与 nullptr之间的关系,nullptr_t 的实现 来源 http://blog.csdn.net/Virtual_Func/article/details/4975 ...

  9. 洛谷 P4070 [SDOI2016]生成魔咒 解题报告

    P4070 [SDOI2016]生成魔咒 题目描述 魔咒串由许多魔咒字符组成,魔咒字符可以用数字表示.例如可以将魔咒字符 \(1\).\(2\) 拼凑起来形成一个魔咒串 \([1,2]\). 一个魔咒 ...

  10. error while loading shared libraries: libmysqlcppconn.so.7: cannot open shared object file: No such file or directory

    1. 即使libmysqlcppconn.so.7和与之相关存在,也报这个错误. 解决方法:临时添加LD_LIBRARY_PATH, 假使 libmysqlcppconn.so在/usr/local/ ...