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

                   
color[i]+=50;//每一盒都加上50ml;

           
}

           
color[0]--;

           
color[1]--;

           
color[2]--;

           
k++;

       
}

       
printf("%d\n",kits);

    }

    return
0;

}

Problem K的更多相关文章

  1. Codeforces Gym 100610 Problem K. Kitchen Robot 状压DP

    Problem K. Kitchen Robot Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10061 ...

  2. Codeforces 1089K - King Kog's Reception - [线段树][2018-2019 ICPC, NEERC, Northern Eurasia Finals Problem K]

    题目链接:https://codeforces.com/contest/1089/problem/K time limit per test: 2 seconds memory limit per t ...

  3. Gym 101981K - Kangaroo Puzzle - [玄学][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem K]

    题目链接:http://codeforces.com/gym/101981/problem/K Your friend has made a computer video game called “K ...

  4. Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem K. UTF-8 Decoder 模拟题

    Problem K. UTF-8 Decoder 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c702 ...

  5. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem K. KMC Attacks 交互题 暴力

    Problem K. KMC Attacks 题目连接: http://codeforces.com/gym/100714 Description Warrant VI is a remote pla ...

  6. XVII Open Cup named after E.V. Pankratiev Grand Prix of Moscow Workshops, Sunday, April 23, 2017 Problem K. Piecemaking

    题目:Problem K. PiecemakingInput file: standard inputOutput file: standard outputTime limit: 1 secondM ...

  7. 2018 Multi-University Training Contest 4 Problem K. Expression in Memories 【模拟】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6342 Problem K. Expression in Memories Time Limit: 200 ...

  8. HDU 6342.Problem K. Expression in Memories-模拟-巴科斯范式填充 (2018 Multi-University Training Contest 4 1011)

    6342.Problem K. Expression in Memories 这个题就是把?变成其他的使得多项式成立并且没有前导零 官方题解: 没意思,好想咸鱼,直接贴一篇别人的博客,写的很好,比我的 ...

  9. 华农oj Problem K: 负2进制【有技巧构造/待补】

    Problem K: 负2进制 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 51 Solved: 6 [Submit][Status][Web Boa ...

  10. Problem K: 搜索基础之棋盘问题

    Problem K: 搜索基础之棋盘问题 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 92  Solved: 53[Submit][Status][W ...

随机推荐

  1. [解读REST] 4.基于网络应用的架构风格

    上篇文章介绍了一组自洽的术语来描述和解释软件架构:如何利用架构属性评估一个架构风格:以及对于基于网络的应用架构来说,那些架构属性是值得我们重点关注评估的.本篇在以上的基础上,列举一下一些常见的(RES ...

  2. Linux学习——shell编程之环境变量配置文件

    小白学习,在学习中总结! shell编程之环境变量配置文件 一:环境变量配置文件 1 shell编程之环境变量配置 变量类型: 用户自定义变量(本地变量) 环境变量 :定义每个用户的操作环境,如pat ...

  3. Codeforces Round #410 (Div. 2)C. Mike and gcd problem

    题目连接:http://codeforces.com/contest/798/problem/C C. Mike and gcd problem time limit per test 2 secon ...

  4. Python cPickle模块

    新博客地址:http://gorthon.sinaapp.com/ 持久性就是指保持对象,甚至在多次执行同一程序之间也保持对象.通过本文,您会对 Python对象的各种持久性机制(从关系数据库到 Py ...

  5. IIS 500错误或无法显示此网页解决方法

    不知道是不是XP版本的原故,发现越来越多的XP系统装好IIS后连默认网站都打不开,(其他系统没有注意)出现几个大字,IIS 500错误.相信碰到这个问题的人都深有体会,确实很烦人.卸了IIS重装也是不 ...

  6. tomcat 内存大小配置

    Tomcat本身不能直接在计算机上运行,需要依赖于硬件基础之上的操作系统和一个java虚拟机.JAVA程序启动时JVM都会分配一个初始内存和最大内存给这个应用程序.这个初始内存和最大内存在一定程度都会 ...

  7. webpack 的使用1

    进入指定文件夹  npm init 安装 npm install webapck --save-dev 根目录下新建hello.js 将文件打包到指定文件  Asset :打包成的文件名称 Chunk ...

  8. MySQL的备份与还原以及常用数据库查看命令

    MySQL命令行导出数据库: 1,进入MySQL目录下的bin文件夹:cd MySQL中到bin文件夹的目录 如我输入的命令行:cd C:\Program Files\MySQL\MySQL Serv ...

  9. Spring MVC Ajax 嵌套表单数据的提交

    概述 在一些场景里,某个大表单里常常嵌套着一个或若干个小逻辑块,比如以下表单里"设计预审"中包括了一个子模块表单"拟定款项". 在这种情况下该怎么去设计实体类以 ...

  10. ABAP字符串的加密与解密

    FIEB_PASSWORD_DECRYPT:字符串解密:FIEB_PASSWORD_ENCRYPT:字符串加密.旧版本的可以用. PARAMETERS:str1 type char32 OBLIGAT ...