POJ 2709

来源:互联网 发布:2016年网络交易额 编辑:程序博客网 时间:2024/06/09 18:49
Painter
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 2710 Accepted: 1706

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 07 25 60 400 250 0 60 0 5004 90 95 75 95 104 90 95 75 95 115 0 0 0 0 0 3330

Sample Output

28234

Source

Mid-Central USA 2005
题意:一套涂料有3~12种颜色,每种颜色50ml。Emily上课需要n种颜色的涂料,第i种颜色需要color[i]ml,此外,Emily还需要grayml的灰色涂料,每ml灰色的涂料需要3种不同颜色的其他涂料各1ml融合而成。问至少需要买几套涂料?
贪心,1ml  1ml去转化。
#include <cstdio>#include <cmath>#include <algorithm>#include <iostream>#include <cstring>#include <map>#include <string>#include <stack>#include <cctype>#include <vector>#include <queue>#include <set>using namespace std;//#define Online_Judge#define outstars cout << "***********************" << endl;#define clr(a,b) memset(a,b,sizeof(a))#define lson l , mid  , rt << 1#define rson mid + 1 , r , rt << 1|1#define FOR(i , x , n) for(int i = (x) ; i < (n) ; i++)#define FORR(i , x , n) for(int i = (x) ; i <= (n) ; i++)#define REP(i , x , n) for(int i = (x) ; i > (n) ; i--)#define REPP(i ,x , n) for(int i = (x) ; i >= (n) ; i--)#define mid ((l + r) >> 1)#define mk make_pairconst int MAXN = 25;const int maxw = 10000000 + 20;const int MAXNNODE = 10000 +10;const long long LLMAX = 0x7fffffffffffffffLL;const long long LLMIN = 0x8000000000000000LL;const int INF = 0x7fffffff;const int IMIN = 0x80000000;#define eps 1e-8#define mod 10007typedef long long LL;const double PI = acos(-1.0);typedef double D;typedef pair<int , int> pii;int a[15];int main(){    //ios::sync_with_stdio(false);#ifdef Online_Judge    freopen("in.txt","r",stdin);    freopen("out.txt","w",stdout);#endif // Online_Judge    int n , grey;    while(~scanf("%d" , &n) , n)    {        FOR(i , 0 , n)        {            scanf("%d" , &a[i]);        }        scanf("%d" , &grey);        sort(a , a + n);        int ans = 0 , maxn = 0;        while(maxn < a[n - 1])        {            ans ++;            maxn += 50;        }        while(1)        {            while(a[2] < maxn && grey > 0)            {                a[0] ++ ;                a[1] ++ ;                a[2] ++ ;                grey--;                sort(a , a + n);            }            if(grey == 0)break;            ans ++;            maxn += 50;        }        printf("%d\n" , ans);    }    return 0;}