HDU2730_Painter_贪心
来源:互联网 发布:linux 没有service 编辑:程序博客网 时间:2024/06/03 21:13
Painter
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 109 Accepted Submission(s): 62
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 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
挺简单的一个贪心题,但弱就是没做出来。
有一个点很关键,灰色要一单位一单位地合成。。。
这一点看似特殊,其实有较大地普适性,一时找不到语言表达。。。
#include<cstdio>#include<algorithm>int c [15];int N;int main (){while(scanf("%d",&N) && N!=0){for(int i=0; i<=N; i++)scanf("%d",c+i);std::sort(c,c+N);while(c[N] > 0){c[0]++,c[1]++,c[2]++;c[N]--;std::sort(c,c+N);}int cnt = c[N-1] / 50;if(c[N-1] % 50) cnt ++ ;printf("%d\n",cnt);}return 0;}
0 0
- HDU2730_Painter_贪心
- 贪心!
- 贪心~
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 解析Struts控制标签二
- <embed>媒体标签
- OrmLite框架 ——OrmLite 入门(android数据库操作框架)
- 每天一个 Linux 命令(29): chgrp命令
- Windows10 多个软件未响应(暴风影音,QQ,优酷,Edge等)
- HDU2730_Painter_贪心
- 深入javascript原型
- Linux IO调度
- 跨域访问-预请求及跨域常见问题
- http range
- poj 3087 shuffle's up bfs
- 1分钟实现“延迟消息”功能(58沈剑)
- Maven-关于在环境变量中配置两个maven的问题
- 单例模式汇总