模拟题,在合成灰色的时候,每次取当前剩余最多的三种颜色,各取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. ElasticSearch 2 (12) - Shard数调优(ElasticSearch性能)

    ElasticSearch 2 (12) - Shard数调优(ElasticSearch性能) 摘要 当创建一个索引的时候,我们经常会面对一个问题:要为索引分配多少个shard?多少个replica ...

  2. 插入排序的C、C++实现

    一.插入排序 有一个已经有序的数据序列,要求在这个已经排好的数据序列中插入一个数,但要求插入后此数据序列仍然有序,这个时候就要用到一种新的排序方法--插入排序法,插入排序的基本操作就是将一个数据插入到 ...

  3. Oracle 标准版 企业版 个人版的区别 转帖

    转帖来源: https://blog.csdn.net/flg_inwind/article/details/2628133 同事方总:http://www.oracle.com/us/corpora ...

  4. developer roadmap

    developer roadmap https://balsamiq.com/ https://balsamiq.com/givingback/free/ https://balsamiq.cloud ...

  5. dubbo的spi机制

    SPI SPI是一种扩展机制,在java中SPI机制被广泛应用,比如Spring中的SpringServletContainerInitializer 使得容器启动的时候SpringServletCo ...

  6. Http建立连接的方式

    1.协议简介 Http 协议:应用层协议 TCP 协议:传输层协议,主要解决如何在IP层之上可靠的传递数据包,使在网络上的另一端收到发端发出的所有包,并且顺序与发出的顺序一致,TCP具有可靠,面向连接 ...

  7. Eclipse 使用 VS快捷键

    这里楼主也是尝试了,只能说一般吧.还是有许多没有改过来... 想要尝试的朋友,可以试试. 首先进入Eclipse 然后 接着 Name:CDT Location:http://download.ecl ...

  8. UVa 572 油田 (dfs)

    The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSu ...

  9. 【刷题】BZOJ 2151 种树

    Description A城市有一个巨大的圆形广场,为了绿化环境和净化空气,市政府决定沿圆形广场外圈种一圈树.园林部门得到指令后,初步规划出n个种树的位置,顺时针编号1到n.并且每个位置都有一个美观度 ...

  10. net 和Mono 构建的HTTP服务框架

    Nancy是一个基于.net 和Mono 构建的HTTP服务框架,是一个非常轻量级的web框架. 设计用于处理 DELETE, GET, HEAD, OPTIONS, POST, PUT 和 PATC ...