- http://blog.csdn.net/CutBug/archive/2009/01/27/3853648.aspx
- using System;
- using System.Collections.Generic;
- namespace Test
- {
- class Program
- {
- static List<int> listCus = new List<int>();
- static List<string> peasons = new List<string>();
- static Dictionary<string, List<int>> result = new Dictionary<string, List<int>>();
- static void Main(string[] args)
- {
- #region 初始化数据
- int m = 4230;
- int n = 50;
- for (int i = 0; i < m; i++)
- {
- listCus.Add(i);
- }
- Console.WriteLine("分配结果:");
- for (int j = 0; j < n; j++)
- {
- string t = (j+1).ToString().PadLeft(12, '0');
- peasons.Add(t);
- result.Add(t, new List<int>());
- }
- #endregion
- #region 算法部分
- int iAv = m / n;
- int iMod = m % n;
- int it = 0 ;
- int ll = 0 ;
- foreach (string k in result.Keys)
- {
- ll = iMod > 0 ? 1 : 0;
- result[k].AddRange(listCus.GetRange(it, iAv + ll));
- it += iAv;
- --iMod;
- Console.WriteLine("{0}:{1}",k,result[k].Count);
- }
- #endregion
- }
- }
- }
平均分配算法
最新推荐文章于 2023-09-06 17:02:42 发布