日期:2014-05-18  浏览次数:20667 次

求算法!(急)
现我有规则如下:
如果买商品A+B任意组合数量等于2,则赠D一个
(可能1*A+1*B=2,2*A+0*B=2,0*A+2*B=2)
如果买商品B       数量等于2,               则赠E一个
如果买商品C       数量等于2,               则赠F一个

现我买A商品2个,B商品2个,C商品2个
如何求得我可能得到的赠品及数量?


各位高手请给出解?谢谢

------解决方案--------------------
UP先~!
------解决方案--------------------
没说明白
1*A+2*B=3是不是得D和E?
------解决方案--------------------
组合一次后,A和B都要减去相应进行组合的数量吧.真拗口.
就是说有10个A10个B,1A+1B后,在组合就是9个A和9个B了吧
------解决方案--------------------
路过,帮顶
------解决方案--------------------
有几种可能 可以给选择让用户挑
------解决方案--------------------
static void Main(string[] args)
{
Program p = new Program();
int[] def = p.ok(2, 3, 5);
foreach (int i in def)
{
Console.WriteLine(i);
}
Console.ReadKey();
}

private int[] ok(int a, int b, int c)
{
int[] def = new int[3];
def[0] = (a + b) / 2;
def[1] = b / 2;
def[2] = c / 2;
return def;
}
------解决方案--------------------
static void Main(string[] args)
{
Program p = new Program();
int[] def = p.ok(2, 3, 5);
foreach (int i in def)
{
Console.WriteLine(i);
}
Console.ReadKey();
}

private int[] ok(int a, int b, int c)
{
int[] def = new int[3];
def[0] = (a + b) / 2;
def[1] = b / 2;
def[2] = c / 2;
return def;
}

是等于或大于是吧。。如果只是等于的话。那么就太简单了。。。直接减个2看是不是等于0。。。
------解决方案--------------------
有以下可能:
1、3个D
2、2个D和1个E
3、2个D和1个F
4、1个D和1个E和1个F


------解决方案--------------------
让用户自己选. 根据在去减
------解决方案--------------------
public enum FavorFirstChoice
{
A,
B,
Unknown
}

public enum Largess
{
D,
E,
F
}
private Dictionary <string, int> _goods;

_goods = new Dictionary <string, int> ();
_goods.Add( "A ", 2);
_goods.Add( "B ", 2);
_goods.Add( "C ", 2);

Dictionary <string, int> test = LargessArithmetic(new string[] { "D ", "E ", "F " }, FavorFirstChoice.A);

private Dictionary <string, int> LargessArithmetic(string[] largessSerials, FavorFirstChoice favor)
{
Dictionary <string, int> ret = new Dictionary <string, int> ();
foreach (string largess in largessSerials)
{
MethodInfo vMethodInfo = this.GetType().GetMethod( "LargessCalc ", BindingFlags.Instance | BindingFlags.NonPublic);