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. 【转】个人总结-网络安全学习和CTF必不可少的一些网站

    转自:http://blog.csdn.net/ida0918/article/details/52730662 学习的地方很多,不能一一列举,一些优秀的网址和博客可能也没有提到,大家补充吧:P就简单 ...

  2. firefox下reset()不好使的问题

    最近在测试项目时发现,在firefox下,form.reset()方法对于隐藏的<input>等不起效果,导致程序中出现了错误,以下面为例: js代码: document.agentFor ...

  3. websevice之三要素

    SOAP(Simple Object Access Protocol).WSDL(WebServicesDescriptionLanguage).UDDI(UniversalDescriptionDi ...

  4. jquery日期和时间的插件精确到秒

    首先.html5提供了input的time类型,使我们可以通过input框输入日期,但是如果我们的需求是这个时间需要明确到几时几分几秒的,那html5就没有办法满足我们的需求了,就需要使用jQuery ...

  5. OC基础:block.字面量 分类: ios学习 OC 2015-06-22 19:08 155人阅读 评论(0) 收藏

    block 块语法,可以用block去保存一段代码,或者封装一段代码. block 实际是由c语言实现的,执行效率很高. block 实际借鉴了函数指针的语法. block,在多线程.异步任务,集合遍 ...

  6. STM32 LSM6DSL 陀螺仪数据采集

    /************************************************************************************ * STM32 LSM6DS ...

  7. 如何查看linux系统的版本信息

    前言 有时候需要查看linux系统的版本信息,本文将对此简单介绍. 方法 1.输入"uname -a ",可显示电脑以及操作系统的相关信息. 2.输入"cat /etc/ ...

  8. windows7所有版本迅雷地址下载集合(含32位和64位) - imsoft.cnblogs

    Windows7 SP1旗舰版 32位官方原版下载: ed2k://|file|/cn_windows_7_ultimate_with_sp1_x86_dvd_618763.iso|265187737 ...

  9. 线程池、及使用场景、线程安全封装、ConcurrentHashMap应用场景

    https://blog.csdn.net/sinbadfreedom/article/details/80467253  :1.HashMap与ConcurrentHashMap的区别与应用场景 h ...

  10. 【maven】使用import scope解决maven继承(单)问题

    测试环境 maven 3.3.9 想必大家在做SpringBoot应用的时候,都会有如下代码: <parent> <groupId>org.springframework.bo ...