Problem K
Problem 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.< br>
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
题意:给你一个颜料盒,里面有n中颜料,每种颜色50ml,唯独没有灰色,但是x ml灰色可由任意三种其他颜色x
ml混合而成,现在给出各个颜色的需求量,让你求最少需要几盒颜料;
解体过程:刚开始以为给出的数字就是给出的每盒颜料中每种颜料的量,就找不到其他颜料的需求了,后来仔细看了看题意才明白是给出的数字就是颜色的需求量,将颜料盒按照颜料的多少按照从小到大的顺序排序,每次拿出前三个(最多的三个)来配灰色,有一种颜色<=0了就集体加50ml(加一盒);
感悟:英语是硬伤,不能耐得住性子看题意啊;
代码(G++
0ms)
#include
#include
#include
#include
#define maxn 20
using namespace std;
bool comp(const int &a,const int &b)
{
return
a>b;
}
int find_max(int color[],int n)
{
int
s=-1;
for(int
i=0;i
{
if(color[i]>s)
s=color[i];
}
return
s;
}
int main()
{
//freopen("in.txt", "r", stdin);
int
n,color[maxn],gray,kits=0,maxneed=0;
while(~scanf("%d",&n)&&n)
{
kits=maxneed=0;
for(int i=0;i
scanf("%d",&color[i]);
scanf("%d",&gray);
maxneed=find_max(color,n);
kits=maxneedP?maxneed/50+1:maxneed/50;//先满足别的颜色需求;
for(int i=0;i
color[i]=kits*50-color[i];//这是按照别的需求加满颜料之后的各种颜料
//的数量
int k=0;
while(true)//开始混合灰色的
{
if(k>=gray)
break;
sort(color,color+n,comp);
if(color[0]<=0||color[1]<=0||color[2]<=0)//如果有一种颜料不够了
{
kits++;
for(int i=0;i
#include
#include
#include
#define maxn 20
using namespace std;
bool comp(const int &a,const int &b)
{
}
int find_max(int color[],int n)
{
}
int main()
{