Painter
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3157   Accepted: 1962

Description

The local toy store sells small fingerpainting kits with between three and twelve 50ml bottles of paint, each a different color. The paints are bright and fun to work with, and have the useful property that if you mix X ml each of any three different colors, you get X ml of gray. (The paints are thick and "airy", almost like cake frosting, and when you mix them together the volume doesn't increase, the paint just gets more dense.) None of the individual colors are gray; the only way to get gray is by mixing exactly three distinct colors, but it doesn't matter which three. Your friend Emily is an elementary school teacher and every Friday she does a fingerpainting project with her class. Given the number of different colors needed, the amount of each color, and the amount of gray, your job is to calculate the number of kits needed for her class.

Input

The input consists of one or more test cases, followed by a line containing only zero that signals the end of the input. Each test case consists of a single line of five or more integers, which are separated by a space. The first integer N is the number of different colors (3 <= N <= 12). Following that are N different nonnegative integers, each at most 1,000, that specify the amount of each color needed. Last is a nonnegative integer G <= 1,000 that specifies the amount of gray needed. All quantities are in ml. 

Output

For each test case, output the smallest number of fingerpainting kits sufficient to provide the required amounts of all the colors and gray. Note that all grays are considered equal, so in order to find the minimum number of kits for a test case you may need to make grays using different combinations of three distinct colors.

Sample Input

3 40 95 21 0
7 25 60 400 250 0 60 0 500
4 90 95 75 95 10
4 90 95 75 95 11
5 0 0 0 0 0 333
0

Sample Output

2
8
2
3
4
Emily 要买N种颜料,她可以到商店里面买,但是灰色是在商店里买不到的。但是可以用任意三种颜料配成(不包括灰色),现在给出Emily想要的N种颜色的量以及灰色的量,问Emily最少要买多少份颜料(每份颜料包括所有她想要的颜料(当然不包括灰色),每种颜料每瓶50ml)
思路:贪心,首先先把不是灰色的其它n种颜料的量先满足,得到相应的剩余的各种颜色的颜料的量;然后用这些量去匹配灰色的量,当然每次是取最大量的三种颜色的颜料,假如得到的量等于了所需要的灰色的量,就得到了结果,否则一直搞,当一些颜料的量为0,无法合成灰色的时候,结果再加一;
 #include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
int n;
int i;
int a[];
int t;
int num;
while (cin >> n && n)
{
for (i = ; i <= n; i++) cin >> a[i];
cin >> t;
num = ;
sort(a + , a + + n);
int k = a[n] / ;
if (k* < a[n]) k++;//先配自己的颜料
for (i = ; i <= n; i++)
{
a[i] = k * - a[i];
}
num += k;
sort(a + , a + + n);//要排序切记
while (t--)
{
bool f = ;
for (i = n; i >=n-; i--)
{
a[i]--;
if (a[i] < && f == )//如果不够了
{
f = ;
}
}
if (f)
{
num++;//不够就加一套
for (i = ; i<=n;i++)
{
a[i] += ; }
}
sort(a + , a + + n);//要排序
}
cout << num << endl;
}
return ;
}

POJ 2706 Painter的更多相关文章

  1. poj 1681 Painter's Problem

    Painter's Problem 题意:给一个n*n(1 <= n <= 15)具有初始颜色(颜色只有yellow&white两种,即01矩阵)的square染色,每次对一个方格 ...

  2. POJ 1681 Painter's Problem 【高斯消元 二进制枚举】

    任意门:http://poj.org/problem?id=1681 Painter's Problem Time Limit: 1000MS   Memory Limit: 10000K Total ...

  3. OpenJudge 2813 画家问题 / Poj 1681 Painter's Problem

    1.链接地址: http://bailian.openjudge.cn/practice/2813 http://poj.org/problem?id=1681 2.题目: 总时间限制: 1000ms ...

  4. POJ 1681 Painter's Problem(高斯消元+枚举自由变元)

    http://poj.org/problem?id=1681 题意:有一块只有黄白颜色的n*n的板子,每次刷一块格子时,上下左右都会改变颜色,求最少刷几次可以使得全部变成黄色. 思路: 这道题目也就是 ...

  5. poj 1681 Painter&#39;s Problem(高斯消元)

    id=1681">http://poj.org/problem? id=1681 求最少经过的步数使得输入的矩阵全变为y. 思路:高斯消元求出自由变元.然后枚举自由变元,求出最优值. ...

  6. POJ 1681 Painter's Problem (高斯消元)

    题目链接 题意:有一面墙每个格子有黄白两种颜色,刷墙每次刷一格会将上下左右中五个格子变色,求最少的刷方法使得所有的格子都变成yellow. 题解:通过打表我们可以得知4*4的一共有4个自由变元,那么我 ...

  7. POJ 1681 Painter's Problem (高斯消元 枚举自由变元求最小的步数)

    题目链接 题意: 一个n*n 的木板 ,每个格子 都 可以 染成 白色和黄色,( 一旦我们对也个格子染色 ,他的上下左右 都将改变颜色): 给定一个初始状态 , 求将 所有的 格子 染成黄色 最少需要 ...

  8. POJ 1681 Painter's Problem [高斯消元XOR]

    同上题 需要判断无解 需要求最小按几次,正确做法是枚举自由元的所有取值来遍历变量的所有取值取合法的最小值,然而听说数据太弱自由元全0就可以就水过去吧.... #include <iostream ...

  9. poj很好很有层次感(转)

    OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 30 ...

随机推荐

  1. L1-015 跟奥巴马一起画方块

    美国总统奥巴马不仅呼吁所有人都学习编程,甚至以身作则编写代码,成为美国历史上首位编写计算机代码的总统.2014年底,为庆祝“计算机科学教育周”正式启动,奥巴马编写了很简单的计算机代码:在屏幕上画一个正 ...

  2. 和不安全的Android说再见,Google为它添加新铠甲

    伴随着最近被曝出的Heartbleed漏洞,安全问题再次成为网络上的热点话题.虽然Android的安全性并没有外界传言的那样脆弱,但Google还是在继续为其增加防护措施.根据Android官方博客的 ...

  3. ES Log4J配置信息

    # 配置RollingFileappender appender.rolling.type = RollingFile appender.rolling.name = rolling # 日志名称 / ...

  4. STL标准库-迭代器适配器

    技术在于交流.沟通,本文为博主原创文章转载请注明出处并保持作品的完整性 这次主要介绍一下迭代器适配器.以reverse_iterator(反向迭代器),insert_iterator(插入迭代器),o ...

  5. zabbix监控系统的配置

    一.zabbix介绍 zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案. zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制以让系 ...

  6. webpack 性能优化 -- 待续

    文章 这篇文章挺不错的, 各方面优化都提到了, 有空研究下 文章 这个文章提出 , 增量打包用 webpack-watch 会让你打包速度飞快,  react不参与打包, 不require, 而是放在 ...

  7. phpstorm 破解方法

    前提概要:我收到博友:3102009292 的消息,发给我另一个破解PHPstorm的方法,我亲测有效,方便快捷,在和博友商量后,决定加入我的本文章中,供更多的开发者参考,话不多说,重点来了. 按照P ...

  8. 解决:People下面选择分享可见联系人,选择多个联系人后通过短信分享,短信中只显示一个联系人

    问题描述: [操作步骤]:People下导入导出中选择分享可见联系人,选择多个联系人后通过短信分享 [测试结果]:短信中只能显示一个联系人 [预期结果]:可以显示多个联系人 经过代码分析,从compo ...

  9. nwjs问题总结

    1.iframe中不支持flash解决方法: nw初始化中加入代码: // 设置flashplayer在iframe中可用 chrome.contentSettings.plugins.set({ p ...

  10. Locust 测试结果通过Matplotlib生成趋势图

    目的: 相信大家对于使用Loadrunner测试后的结果分析详细程度还是有比较深刻的感受的,每个请求,每个事务点等都会有各自的趋势指标,在同一张图标中展示.如下图: 而Locust自身提供的chart ...