模拟题,在合成灰色的时候,每次取当前剩余最多的三种颜色,各取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. 自定义SQL语句

    在用@query写了sql语句后,返回的结果集不能自动转换为自定义的对象. 百度有一篇博客,解决方案是直接在sql语句里实例化对象,我用了,但是语法错误,又谷歌了下,sql语句里是不能这样写的,这是h ...

  2. PAT 甲级 1087 All Roads Lead to Rome

    https://pintia.cn/problem-sets/994805342720868352/problems/994805379664297984 Indeed there are many ...

  3. TCP/IP之蓟辽督师 转

    原创: 刘欣 码农翻身 2016-11-07 本文续<TCP/IP之大明内阁>, 不了解背景的同学可以先看看上一篇文章, 当然这篇也是<TCP/IP之大明邮差>的前传, 主要讲 ...

  4. Android Sensor——传感器

    Android SDK 支持的传感器类型,在Sensor类中的定义: 01.TYPE_ACCELEROMETER  : 加速传感器(硬件) 02.TYPE_AMBIENT_TEMPERATURE : ...

  5. 深入理解ajax系列第七篇——传递JSON

    前面的话 虽然ajax全称是asynchronous javascript and XML.但目前使用ajax技术时,传递JSON已经成为事实上的标准.因为相较于XML而言,JSON简单且方便.本文将 ...

  6. 小菜菜mysql练习解读分析1——查询" 01 "课程比" 02 "课程成绩高的学生的信息及课程分数

    查询" 01 "课程比" 02 "课程成绩高的学生的信息及课程分数 好的,第一道题,刚开始做,就栽了个跟头,爽歪歪,至于怎么栽跟头的 ——需要分析题目,查询的是 ...

  7. IDEA中新建Module时Module name、Content root、Module file location的含义

    如下图测试: 最开始默认情况下,Content root.Module file location两行,最末尾的数据跟Module name是相同的. 现在对三行数据,强制进行不同的命名,Finish ...

  8. Maven父子项目配置-多模块(multi-modules)结构

    Maven创建父子项目,这个项目指的是eclipse中的project,idea中的module.使用idea创建的话很简单,可以直接选择项目的父亲,这些网上有很多资料的. 这里说一下创建父子项目时, ...

  9. office2013 激活方式

    1.下载   KMSpico_setup 2.关闭所有杀毒 3.打开  KMSpico_setup.exe 安装,下一步下一步,完成 4.打开word2013看下还有没弹出过期,没有即成功 5.卸载k ...

  10. 【题解】 P1879 玉米田Corn Fields (动态规划,状态压缩)

    题目描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ...