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. 微信分享自定义标题和图片的js

    <script> document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() { window.sh ...

  2. Sqoop2安装

    下载 http://www-us.apache.org/dist/sqoop/ 打开以上链接,开始下载sqoop2   下载后得到:sqoop-1.99.7-bin-hadoop200.tar.gz文 ...

  3. 玩转X-CTR100 l STM32F4 l 舵机控制

    我造轮子,你造车,创客一起造起来!塔克创新资讯[塔克社区 www.xtark.cn ][塔克博客 www.cnblogs.com/xtark/ ] 本文介绍X-CTR100控制器的舵机控制,X-CTR ...

  4. 玩转X-CTR100 | X-Assistant串口助手控制功能

      更多塔克创新资讯欢迎登陆[塔克社区 www.xtark.cn ][塔克博客 www.cnblogs.com/xtark/ ]       X-CTR100控制器配套的X-Assistant串口调试 ...

  5. DevExpress v18.1新版亮点——ASP.NET篇(一)

    用户界面套包DevExpress v18.1日前终于正式发布,本站将以连载的形式为大家介绍各版本新增内容.本文将介绍了DevExpress ASP.NET v18.1 的新功能,快来下载试用新版本!点 ...

  6. html内容滚动

    <marquee srolldelay="50" direction="up"></marquee> 滚动标签<marquee&g ...

  7. js创建表单并提交

    1.脚本 Util = { post : function(URL, PARAMS){ //虚拟表单实现post提交 var temp = document.createElement("f ...

  8. kmp算法中的nextval实例解释

    求nextval数组值有两种方法,一种是不依赖next数组值直接用观察法求得,一种方法是根据next数组值进行推理,两种方法均可使用,视更喜欢哪种方法而定. 本文主要分析nextval数组值的第二种方 ...

  9. android编译环境安装

    Android 编译环境安装 安装 Java 6 安装 Java 6 安装依赖包 (Ubuntu 12.04) $ sudo apt-get install git gnupg flex bison ...

  10. MyEclipse怎么导入导出项目

    MyEclipse怎么导入导出项目 | 浏览:25271 | 更新:2012-06-06 17:48 1 2 3 4 5 6 7 分步阅读 MyEclipse,是一个十分优秀的功能强大的JavaEE的 ...