Painter
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 4808 | Accepted: 2793 |
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
题意:
给你N种颜色,每次一买就是一整套,其中每种颜色(没有灰色)都有50ml,然后3种颜色各 x ml(一共3x ml)混合可得到 x ml的灰色颜料
然后给出每种颜色的需求量,求一共最少要买几套?
(3<=N<= 12 每种颜色需求量保证不超过1000)
还是题见得不够多呀,刚开始根本没往这方面想,就一直在纠结怎么减掉一个整体了
首先,是对于每种颜料(除灰色),对它的需求一定是由它自己最开始买的套装中提供的,
灰色来自其他颜色,因为不清楚是哪三种颜色混在一起,也不清楚那种颜色混多少,
所以就一毫升一毫升地模拟,然后排序,然后再一毫升,再排序(感觉有点暴力,但是N很小就还好)
Code:
Status | Accepted |
---|---|
Memory | 684kB |
Length | 1111 |
Lang | G++ |
Submitted | 2017-07-13 11:36:53 |
Shared |
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int Max = 12;
const int INF = 0x3f3f3f3f;
int N;
int A[Max + 5], lft[Max + 5];
void getint(int & num){
char c; int flg = 1; num = 0;
while((c = getchar()) < '0' || c > '9') if(c == '-') flg = -1;
while(c >= '0' && c <= '9') { num = num * 10 + c - 48; c = getchar();}
num *= flg;
}
int main(){
while(~scanf("%d", &N) && N){
int Ans = 0;
for(int i = 1; i <= N; ++ i){
getint(A[i]);
lft[i] = A[i] / 50 * 50 < A[i] ? A[i] / 50 + 1 : A[i] / 50;
Ans = max(Ans, lft[i]);
}
getint(A[N + 1]);
int set = INF;
for(int i = 1; i <= N; ++ i){
lft[i] = Ans * 50 - A[i];
set = min(set, lft[i]);
}
if(set >= A[N + 1]) Ans = Ans;
else {
sort(lft + 1, lft + 1+ N);
for(int i = 1; i <= A[N + 1]; ++ i){
if(! lft[N - 2]){
++ Ans;
for(int j = 1; j <= N; ++ j)
lft[j] += 50;
}
if(lft[N - 2]){
-- lft[N], -- lft[N - 1], -- lft[N - 2];
sort(lft + 1, lft + 1+ N);
}
}
}
printf("%d\n", Ans);
}
return 0;
}