SDAU 贪心专题 10 颜料问题
2016-03-21 09:34
337 查看
1:问题描述
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.
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
2:大致题意
先输入n,后面有n个数据代表有n个除灰色以外的颜色,还有一个数据代表需要灰色颜料的数量。1组颜料是每种颜色50ML,不过买不到灰色的,所以需要你自己配,任意3种1ml的颜色可以配成1ml的灰色。求出最少的组数。
3:思路
找出最大的颜料数除以50,判断要不要进1。得到组数,然后看看是不是可以配出灰色,不够的话再加一组。
我觉得最一个样例给的特别好,333ml灰色的为什么是只需要4组那?
4*5*50/3=333。兑灰色的时候 要一毫升一毫升的配。这样可以将所有的颜料都用完,即可求出最少组数。
4:感想
只要想到需要一毫升一毫升的配就简单啦,思路还是最重要的。
5:ac代码
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.
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
2:大致题意
先输入n,后面有n个数据代表有n个除灰色以外的颜色,还有一个数据代表需要灰色颜料的数量。1组颜料是每种颜色50ML,不过买不到灰色的,所以需要你自己配,任意3种1ml的颜色可以配成1ml的灰色。求出最少的组数。
3:思路
找出最大的颜料数除以50,判断要不要进1。得到组数,然后看看是不是可以配出灰色,不够的话再加一组。
我觉得最一个样例给的特别好,333ml灰色的为什么是只需要4组那?
4*5*50/3=333。兑灰色的时候 要一毫升一毫升的配。这样可以将所有的颜料都用完,即可求出最少组数。
4:感想
只要想到需要一毫升一毫升的配就简单啦,思路还是最重要的。
5:ac代码
#include <cstdio> #include<iostream> #include<stdio.h> #include<vector> #include<algorithm> #include<numeric> #include<math.h> #include<string.h> #include<map> #include<set> #include<vector> #include<iomanip> using namespace std; bool cmp(int a,int b) { return a>b; } int main() { int n,h,i,a,t; vector<int> v; int z; while(cin>>n&&n!=0) { v.clear(); for(i=0;i<n;i++) { cin>>a; v.push_back(a); } cin>>h; sort(v.begin(),v.end()); if(v[n-1]%50==0) t=v[n-1]/50; else t=v[n-1]/50+1; for(i=0;i<n;i++) { v[i]=t*50-v[i]; } //cout<<v[0]<<" "<<v[1]<<" "<<v[2]<<" "<<endl; while(h>0) { sort(v.begin(),v.end(),cmp); if(v[2]==0) { t++; for(i=0;i<n;i++) v[i]+=50; } h--;v[0]--;v[1]--;v[2]--; } cout<<t<<endl; } return 0; }
相关文章推荐
- 简单的四则运算
- 数的奇偶性
- ACM网址
- 1272 小希的迷宫
- 1272 小希的迷宫
- hdu 1250 大数相加并用数组储存
- 矩阵的乘法操作
- 蚂蚁爬行问题
- 蚂蚁爬行问题
- 求两个数的最大公约数【ACM基础题】
- 打印出二进制中所有1的位置
- 杭电题目---一只小蜜蜂
- HDOJ 1002 A + B Problem II (Big Numbers Addition)
- 初学ACM - 半数集(Half Set)问题 NOJ 1010 / FOJ 1207
- 初学ACM - 组合数学基础题目PKU 1833
- POJ ACM 1002
- POJ 2635 The Embarrassed Cryptographe
- POJ 3292 Semi-prime H-numbers
- POJ 2773 HAPPY 2006
- POJ 3090 Visible Lattice Points