zoukankan      html  css  js  c++  java
  • 按照不同节点优先级,分布不同任务算法

    回到家里,看了一下第一个for内部的for完全是多余的,优化为:

     1             List<int> configs = new List<int> { 1, 2, 1 };
     2 
     3             List<int> items = new List<int> { 
     4                 1,2,3,
     5                 4,5,6,
     6                 7,8,9
     7             };
     8 
     9             int skipCount = 0;
    10 
    11             for (int i = 0; i < configs.Count - 1; i++)
    12             {
    13                 int count = (int)(((decimal)configs[i] / configs.Sum()) * items.Count);
    14 
    15                 List<int> tempItems = items.Skip(skipCount).Take(count).ToList();
    16 
    17                 Console.WriteLine("index:{0}-skip:{1}-take:{2}---------------------------", i, skipCount, count);
    18                 foreach (var tempItem in tempItems)
    19                 {
    20                     Console.WriteLine(tempItem);
    21                 }
    22                 Console.WriteLine("------------------------------------------------------");
    23 
    24                 skipCount += count;
    25             }
    26 
    27             List<int> lastestItems = items.Skip(skipCount).Take(items.Count - skipCount).ToList();
    28             Console.WriteLine("index:{0}-skip:{1}-take:{2}---------------------------", configs.Count - 1, skipCount, items.Count - skipCount);
    29             foreach (var lastestItem in lastestItems)
    30             {
    31                 Console.WriteLine(lastestItem);
    32             }
    33             Console.WriteLine("------------------------------------------------------");
    34 
    35             Console.ReadKey();

    运行结果:

  • 相关阅读:
    123457123456---com.threeObj3.BabyShizi02--- 宝宝识字02
    协议
    123457---com.threeObj.Baobaoshizi01--- 宝宝识字01
    123456---com.twoapp.ErTongNongChangPinTu---儿童农场拼图
    Mysql
    MySQL的四种事务隔离级别
    Git撤销&回滚操作
    java.util.Timer简介
    git常用命令
    BigDecimal转String
  • 原文地址:https://www.cnblogs.com/yy3b2007com/p/4494690.html
Copyright © 2011-2022 走看看