算法求解。。 咨询师 已有数量 排序 差额(上行减下行数量) C 1 1 2 B 3 2 1A 4 3 若分配数为3个,那么从第一行的差额开始减未分配数,将分配数-差额的差存入下行,一直到分配数-差额<=0结束 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 假设a[n]为当前咨询师所拥有的客户,且优先级依次递减b[n]分配指控量,b[0] = 1, else b[i] = a[i] - a[i - 1];来了客户,从b[n-1]开始往前检查,发现b[i]不为0,则a[i] += 1,同时再次执行b[0] = 1, else b[i] = a[i] - a[i - 1]; 有漏洞当出现中间大,两边小就不行了那就只好找出a[maxA]b[i] = a[maxA] - a[i]来了客户就找b[maxB],a[maxB] += 1再次执行找出a[maxA] b[i] = a[maxA] - a[i] 先按数量排序,数量相同按权值排序比如咨询师 权值 数量A 1 4B 2 3C 3 1排序后咨询师 权值 数量C 3 1B 2 3A 1 4C增加2个后咨询师 权值 数量B 2 3C 3 3A 1 4不就行了? List<int> listCus = new List<int>(); List<string> peasons = new List<string>(); Dictionary<string, List<int>> result = new Dictionary<string, List<int>>(); Dictionary<string, int> result2 = new Dictionary<string, int>(); result2.Add("12", 13); result2.Add("2", 12); result2.Add("3", 1); result2.Add("4", 3); result2.Add("5", 33); result2.Add("6", 63); result2.Add("7", 18); foreach (var item in result2) { Response.Write(string.Format("{0}:{1}<br />", item.Key, item.Value)); } Response.Write(string.Format("<hr />")); var lst = result2.OrderBy(r => r.Value).ToList(); int n = 912; //总数 string logKey = string.Empty; var lst2 = new List<KeyValuePair<string, int>>(); int sum = 0;//叠加,合计 计算平均值 lst2.Add(lst[0]); sum += lst[0].Value; for (int i = 1; i < lst.Count; i++) { //判断他是否超过了平均值,如果超过也就没必要计算进去,因为前面数值平分之后也涉及不到它 if ((sum + n) / lst2.Count > lst[i].Value) { lst2.Add(lst[i]); sum += lst[i].Value; } } int ave = (sum + n) / lst2.Count;//平均数 int mo = (sum + n) % lst2.Count;//取余数 int k = 0; while (k < (n - mo)) { foreach (var item in lst2) { if (k >= (n - mo)) { break; } if (result2[item.Key] < ave) { result2[item.Key] += 1; k += 1; } } }//处理余数 余数一般没多少了。就用最简单直接的办法弄了,有没有其它办法处理好呢。 for (int i = 0; i < mo; i++) { lst = result2.OrderBy(r => r.Value).ToList(); result2[lst[0].Key] += 1; } foreach (var item in result2) { Response.Write(string.Format("{0}:{1}<br />", item.Key, item.Value)); }自己试了下,结果还算正确,可是就是不知道有没有其它隐藏问题。有好心大婶路过就指教下 Dictionary<string, List<int>> result = new Dictionary<string, List<int>>(); 好像没在用吧啥东东啊 想要提高效率,不想一个一个分配,那就先把差值的和计算出来比如A 4 0B 3 1C 1 3计算出每个咨询师相对于人数最多的咨询师相差的数量然后把客户减去这个总数比如有10个客户需要分配,10-4=6,分掉4个,只剩6个了剩下6个再平均分,余数再重新分当然这个是总数比差值的和大的情况如果总数不足差值的和,判断到底够几个人分的,再用上面的办法平均分给这几个人,人数多的咨询师就分不到了判断可以写个递归,看到底够哪几个人分 c#.net 打印问题,急。。。 form上怎么绘制一个图片 try 里面怎么写,可以直接跳到相应的 catch 用过OpenGL的朋友帮我 如何判断当前正在运行的进程是被嵌入的? 各位高人,请帮帮忙将这段代码转换一下。 欢迎加入IT讨论群,爱好C#的同志们欢迎加入(11375923) 关于dataset和数据库的问题 winform程序指定平台一定要选x86吗? 通过反射动态SHOW出的窗体 怎么传递参数 我怎么就获取不到数据库的图片啊,大神帮忙看一下! winform的Locked属性只是在设计阶段固定窗口大小,运行时还是可以改变啊
有漏洞当出现中间大,两边小就不行了那就只好找出a[maxA]b[i] = a[maxA] - a[i]来了客户就找b[maxB],a[maxB] += 1再次执行找出a[maxA] b[i] = a[maxA] - a[i]
比如
咨询师 权值 数量
A 1 4
B 2 3
C 3 1
排序后
咨询师 权值 数量
C 3 1
B 2 3
A 1 4
C增加2个后
咨询师 权值 数量
B 2 3
C 3 3
A 1 4
不就行了?
List<string> peasons = new List<string>();
Dictionary<string, List<int>> result = new Dictionary<string, List<int>>();
Dictionary<string, int> result2 = new Dictionary<string, int>(); result2.Add("12", 13);
result2.Add("2", 12);
result2.Add("3", 1);
result2.Add("4", 3);
result2.Add("5", 33);
result2.Add("6", 63);
result2.Add("7", 18);
foreach (var item in result2)
{
Response.Write(string.Format("{0}:{1}<br />", item.Key, item.Value));
}
Response.Write(string.Format("<hr />"));
var lst = result2.OrderBy(r => r.Value).ToList();
int n = 912; //总数 string logKey = string.Empty;
var lst2 = new List<KeyValuePair<string, int>>();
int sum = 0;//叠加,合计 计算平均值
lst2.Add(lst[0]);
sum += lst[0].Value;
for (int i = 1; i < lst.Count; i++)
{
//判断他是否超过了平均值,如果超过也就没必要计算进去,因为前面数值平分之后也涉及不到它
if ((sum + n) / lst2.Count > lst[i].Value)
{
lst2.Add(lst[i]);
sum += lst[i].Value;
}
}
int ave = (sum + n) / lst2.Count;//平均数
int mo = (sum + n) % lst2.Count;//取余数 int k = 0;
while (k < (n - mo))
{
foreach (var item in lst2)
{
if (k >= (n - mo))
{
break;
} if (result2[item.Key] < ave)
{
result2[item.Key] += 1;
k += 1; } }
}
//处理余数 余数一般没多少了。就用最简单直接的办法弄了,有没有其它办法处理好呢。
for (int i = 0; i < mo; i++)
{
lst = result2.OrderBy(r => r.Value).ToList();
result2[lst[0].Key] += 1;
}
foreach (var item in result2)
{
Response.Write(string.Format("{0}:{1}<br />", item.Key, item.Value));
}
自己试了下,结果还算正确,可是就是不知道有没有其它隐藏问题。
有好心大婶路过就指教下
比如
A 4 0
B 3 1
C 1 3
计算出每个咨询师相对于人数最多的咨询师相差的数量
然后把客户减去这个总数
比如有10个客户需要分配,10-4=6,分掉4个,只剩6个了
剩下6个再平均分,余数再重新分
当然这个是总数比差值的和大的情况如果总数不足差值的和,判断到底够几个人分的,再用上面的办法平均分给这几个人,人数多的咨询师就分不到了判断可以写个递归,看到底够哪几个人分