简单的贪心
来源:互联网 发布:蜂群算法代码 编辑:程序博客网 时间:2024/06/06 15:58
简单的贪心
Hint
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,后面有n个数据代表有n个除灰色以外的颜色,还有一个数据代表需要灰色颜料的数量。1组颜料是每种颜色50ML,不过买不到灰色的,所以需要你自己配,任意3种1ml的颜色可以配成1ml的灰色。求出最少的组数。
3:思路 找出最大的颜料数除以50,判断要不要进1。得到组数,然后看看是不是可以配出灰色,不够的话再加一组。 我觉得最一个样例给的特别好,333ml灰色的为什么是只需要4组那? 4*5*50/3=333。兑灰色的时候 要一毫升一毫升的配。这样可以将所有的颜料都用完,即可求出最少组数。
4:感想 只要想到需要一毫升一毫升的配就简单啦,思路还是最重要的。
#include<stdio.h>#include<iostream>#include<algorithm>using namespace std;int a[13],b[13];int main(){ int n; while(scanf("%d",&n)!=-1) { if(n==0) break; for(int i=0; i<n; i++) { scanf("%d",&a[i]); } int m; scanf("%d",&m); sort(a,a+n); int h; h=a[n-1]; int sum=0; if(h%50!=0) sum=h/50+1; else sum=h/50; int p=0; for(int i=0; i<n; i++) { b[i]=50*sum-a[i]; } while(m>0) { sort(b,b+n); if(b[n-3]==0) { sum++; for(int i=0; i<n; i++) { b[i]=b[i]+50; } } else { m--; b[n-1]--; b[n-2]--; b[n-3]--; } } printf("%d\n",sum); }}
0 0
- 简单的贪心 poj1328
- 最简单的贪心
- 简单的贪心
- 简单的贪心
- 喷水装置 简单的贪心
- poj 1065简单的贪心
- 一道简单的贪心算法
- hdu1009简单的贪心问题
- 简单的贪心题 c
- POJ 3069 简单的贪心
- 简单贪心
- 简单贪心
- 送货的难题->简单的贪心
- 简单的排序+贪心 pku 1089_Intervals
- HDOJ 1009 FatMouse' Trade简单的贪心
- poj 1065Wooden Sticks (简单的贪心)
- poj 1328 Radar Installation (简单的贪心)
- 最简单的贪心法:硬币问题
- 调用系统拍照 -- 踩过的坑
- SUSE 11 SP2下给普通用户加上sudo命令权限
- linphone-TunnelConfigImpl文件对应的JNI层文件分析
- (三)表的概念
- 旋转数组的最小数字
- 简单的贪心
- Sort(啊哈算法)
- Android开发之仿QQ侧滑删除实现(二)
- hbase 1.1.4增删查改demo
- cdoj 1355 郭大侠与“有何贵干?”
- Tomcat8.x 《设计模式》Facade设计模式的使用->getServletContext()
- NOIP 2006 - 提高组 金明的预算 动态规划(DP)
- linux kernel启动流程
- 总结oninput、onchange与onpropertychange事件的用法和区别