ACM ProblemK
2016-03-27 16:21
218 查看
我现在做的是编号为1010的试题,具体内容如下:
Total Submission(s) : 47 Accepted Submission(s) : 18
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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>
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
[align=left]Sample Output[/align]
简单题意:
每套颜料包3-12种颜料(没有灰色),每种颜料50ml。任意取3种颜料(每种颜料x ml)混合即可得到x ml的灰色颜料增加,给定一套颜料包内颜料种类的数量,每种颜色的总量和所需灰色颜料的量。计算至少使用多少套颜料包。
解题思路:
利用贪心算法对颜料按照容量降序排列,得到最大的颜料量,算出不算灰色时所需的颜料数,然后,计算除了自己所需的,还剩多少去配灰色颜料,再利用贪心算法进行降序排列,找到最大的三个数,如果第三个数大于0,则灰色颜料数和前三种颜料都减1,直到第三个数为0.
编写代码:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool cmp(int a, int b)
{
return a > b;
}
int main()
{
vector<int> v;
int t;
while (cin >> t)
{
if(t == 0)
break;
else
{
int n, total;
for (int i=0; i<t; i++)
{
cin >> n;
v.push_back(n);
}
int grayNum;
cin >> grayNum;
sort(v.begin(), v.end(), cmp);
if (v[0] % 50 == 0)
total = v[0] / 50;
else
total = v[0] / 50 + 1;
for (int i=0; i<t; i++)
{
v[i] = total * 50 - v[i];
}
while(grayNum > 0)
{
sort(v.begin(), v.end(), cmp);
if (v[2] == 0)
{
total++;
for (int i=0; i<t; i++)
{
v[i] += 50;
}
}
else
{
grayNum--;
v[0]--;
v[1]--;
v[2]--;
}
}
cout << total << endl;
v.clear();
}
}
}
Problem K
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)Total Submission(s) : 47 Accepted Submission(s) : 18
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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>
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
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
[align=left]Sample Output[/align]
2 8 2 3 4
简单题意:
每套颜料包3-12种颜料(没有灰色),每种颜料50ml。任意取3种颜料(每种颜料x ml)混合即可得到x ml的灰色颜料增加,给定一套颜料包内颜料种类的数量,每种颜色的总量和所需灰色颜料的量。计算至少使用多少套颜料包。
解题思路:
利用贪心算法对颜料按照容量降序排列,得到最大的颜料量,算出不算灰色时所需的颜料数,然后,计算除了自己所需的,还剩多少去配灰色颜料,再利用贪心算法进行降序排列,找到最大的三个数,如果第三个数大于0,则灰色颜料数和前三种颜料都减1,直到第三个数为0.
编写代码:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool cmp(int a, int b)
{
return a > b;
}
int main()
{
vector<int> v;
int t;
while (cin >> t)
{
if(t == 0)
break;
else
{
int n, total;
for (int i=0; i<t; i++)
{
cin >> n;
v.push_back(n);
}
int grayNum;
cin >> grayNum;
sort(v.begin(), v.end(), cmp);
if (v[0] % 50 == 0)
total = v[0] / 50;
else
total = v[0] / 50 + 1;
for (int i=0; i<t; i++)
{
v[i] = total * 50 - v[i];
}
while(grayNum > 0)
{
sort(v.begin(), v.end(), cmp);
if (v[2] == 0)
{
total++;
for (int i=0; i<t; i++)
{
v[i] += 50;
}
}
else
{
grayNum--;
v[0]--;
v[1]--;
v[2]--;
}
}
cout << total << endl;
v.clear();
}
}
}
相关文章推荐
- iCamera App Kit 使用说明
- rodrigue 公式r-v v-r
- ACM第一次练习—1002C
- 一定要坚持
- BestCoder Round #77 (div.2) -so easy(组合)
- 分享一个 原生javaScript - 用面向对象写的下拉菜单 - DropdownMenu
- 63. Unique Paths II
- python查看类的定义
- 公元2016年3月27日。执行力。
- 函数指针与指针函数
- Struck: Structrued Output Tracking with Kernels 论文笔记
- struts2中的constant配置详解
- 数据库-T-SQL 语句-创建表,删除表,CRUD操作的添加数据,修改数据,删除数据
- mysql Table 'performance_schema.session_variables' doesn't exist
- 基于面向协议MVP模式下的软件设计-iOS篇
- JDBC入门
- 23、Oracle如何连接远程服务器?
- windows消息机制(MFC)
- Linux系统下JavaJDK,Eclipse,Androrid studio的安装教程
- 智能指针(现代 C++)