平均分配算法

  1. http://blog.csdn.net/CutBug/archive/2009/01/27/3853648.aspx
  2. using System;   
  3. using System.Collections.Generic;   
  4. namespace Test   
  5. {   
  6.     class Program    
  7.     {   
  8.         static List<int> listCus = new List<int>();   
  9.         static List<string> peasons = new List<string>();   
  10.         static Dictionary<string, List<int>> result = new Dictionary<string, List<int>>();   
  11.         static void Main(string[] args)   
  12.         {  
  13.             #region 初始化数据   
  14.             int m = 4230;   
  15.             int n = 50;   
  16.             for (int i = 0; i < m; i++)   
  17.             {   
  18.                 listCus.Add(i);   
  19.                    
  20.             }   
  21.             Console.WriteLine("分配结果:");   
  22.             for (int j = 0; j < n; j++)   
  23.             {   
  24.                 string t = (j+1).ToString().PadLeft(12, '0');   
  25.                 peasons.Add(t);   
  26.                 result.Add(t, new List<int>());   
  27.             }  
  28.             #endregion   
  29.  
  30.             #region 算法部分   
  31.             int iAv = m / n;   
  32.             int iMod = m % n;   
  33.             int it = 0 ;   
  34.             int ll = 0 ;   
  35.             foreach (string k in result.Keys)   
  36.             {   
  37.                 ll = iMod > 0 ? 1 : 0;   
  38.                 result[k].AddRange(listCus.GetRange(it, iAv + ll));   
  39.                 it += iAv;   
  40.                 --iMod;   
  41.                 Console.WriteLine("{0}:{1}",k,result[k].Count);   
  42.             }  
  43.             #endregion    
  44.   
  45.         }   
  46.     }   
  47.        
  48. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值