标签:
private static bool DevideInCommon(double[] arrLength, int intCount) { //判断存在负数或0 if (arrLength.Any(i => i <= 0)) { return false; } int intNum = arrLength.Length; double maxAVG = arrLength.Sum() / intCount; int[] arrCount = arrLength.Select(i => Convert.ToInt32(Math.Floor(i / maxAVG))).ToArray(); if (arrCount.Sum() < intCount) { List<double> lstLength = new List<double>(); for (int i = 0; i < arrLength.Length; i++) { for (int j = 1; j < intNum; j++) { double tmpL = arrLength[i] / (arrCount[i] + j); int[] arrCount2 = arrLength.Select(m => Convert.ToInt32(Math.Floor(m / tmpL))).ToArray(); if (arrCount2.Sum() < intCount) { continue; } else { lstLength.Add(tmpL); break; } } } double intResult = lstLength.Max(); Display(arrLength, intResult); } else { Display(arrLength, maxAVG); } return true; }
辅助显示
private static void Display(double[] arrLength, double avgLength) { Console.WriteLine("AVG: " + avgLength); foreach (double len in arrLength) { Console.WriteLine("Length: " + len + " Count: " + Math.Floor(len / avgLength)); } }
希望对你有帮助。
标签:
原文地址:http://www.cnblogs.com/xuqihe/p/4259470.html