TopCoder SRM 609 DIV2 500points

4 篇文章 0 订阅
4 篇文章 0 订阅

Problem Statement

 We have R red, G green, and B blue balls. We want to divide them into as few packages as possible. Each package must contain 1, 2, or 3 balls. Additionally, each package must be either a "normal set" (all balls in the package have the same color), or a "variety set" (no two balls have the same color). Compute and return the smallest possible number of packages.

Definition

 
Class:PackingBallsDiv2
Method:minPacks
Parameters:int, int, int
Returns:int
Method signature:int minPacks(int R, int G, int B)
(be sure your method is public)

Limits

 
Time limit (s):2.000
Memory limit (MB):256

Constraints

-R, G, and B will each be between 1 and 100, inclusive.

Examples

0) 
 
4
2
4
Returns: 4
We have 4 red, 2 green, and 4 blue balls. Clearly, we need at least four packages to store 10 balls. One possibility of using exactly four packages looks as follows: RGB, RG, RR, BBB. (I.e., the first package has 1 ball of each color, the second package has a red and a green ball, and so on.)
1) 
 
1
7
1
Returns: 3
Here the only possible solution is to have one package with RGB and two packages with GGG each.
2) 
 
2
3
5
Returns: 4
3) 
 
78
53
64
Returns: 66
4) 
 
100
100
100
Returns: 100

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.     


有R,G,B,三种颜色的球若干,将其打包,每个包里可放1/2/3个球,打包有两种要求:1.颜色全一样(比如RRR,BBB,GGG,RR,BB,GG,R,G,B),2.不能有颜色相同的(比如RGB,RG,RB,GB可以,而RRG这种就不可以),求最小打包量


方法应该很多,思路是尽量3个球一个包,我的思路是优先RGB包,这样只剩2种颜色,然后3个相同颜色球的包,这样剩的球只能是0+0,0+1,1+1,2+1,2+2五种情况,0+0不用再打包,0+1打1个包,1+1,2+1,2+2打2个包


#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<ctime>
#include<cctype>
#include<cmath>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#define sqr(x) (x)*(x)
#define INF 0x1f1f1f1f
#define PI 3.1415926535
#define mm 

using namespace std;

class PackingBallsDiv2
{
	public:
		int minPacks(int R, int G, int B);
};

int PackingBallsDiv2::minPacks(int R, int G, int B)
{
	int pack=0;
	pack=min(R,min(G,B));
	R-=pack;
	G-=pack;
	B-=pack;
	pack+=((R/3)+(G/3)+(B/3));
	R%=3;
	G%=3;
	B%=3;
	if (R+B+G>0)
	{
	
		if (R+B+G<=2)
		{
			pack+=1;
		}
		else
		{
	
				pack+=2;
		}
	}
	return pack;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值