zoukankan      html  css  js  c++  java
  • C#数组是引用类型, 引用类型一定要实例化

    // lengths = new long[1]; 如果没有使用List转换为array, 那么要用这行代码来实例化数组 lengths.

    
           public static bool GetArrayChunk(double[] data, long[] startLocations, long locationOffset, double lowLimit, 
                int numberOfConsecutivePoints, int minimumSize, out double[] chunks, out long[] lengths)
            {
    
               // lengths = new long[1]; 如果没有使用List转换为array, 那么要用这行代码来实例化数组 lengths.
    
                List<long> lengthsList = new List<long>();
                List<double> chunksList = new List<double>();
                
                for (ulong i = 0; i < (ulong)startLocations.Length; i++ )
                {
                   //GetStartLocationOfLowerData(startLocation[i] + locationOffset, lowLimit,)
                    long start =(long)(startLocations[i] + locationOffset);
                    long end = 0;
                    long k = 0;
                    //ulong endOfIteration;
                    //endOfIteration = 
                    for(long j = start; j < (long)data.Length; j++)
                    {
     
                            if (data[j] > lowLimit)
                            {
                                chunksList.Add(data[j]);
                                //i++;
                            }
                            else
                            {
                                //mr:: 如果找到了连续5个点低于lowlimit,说明找到了一个lowerLocation
                                if (IsLowerlocation(data, j, lowLimit, numberOfConsecutivePoints))
                                    break;
                                else
                                {
                                    chunksList.Add(data[j]);
                                }
    
                            }
    
                            end = j;
    
                    }
    
                    //mr:: 在一个chunk出来过程中,如果出现lowerlocation之前累积保存的点数量不到minimumSize, 则剔除这些数据.
                    if ((end - start) < minimumSize)
                    {
                        //mr?? 数据范围与数据类型的限制
                        chunksList.RemoveRange((int)start, (int)(end - start));
                    }
                    else
                    {
                        //mr:: 记录下一个合格chunk的长度
                        k++;
                       // lengths[k] = end - start;
    
                        lengthsList.Add(end - start);
                    }
                }
    
                //if (chunksList.)
                chunks = chunksList.ToArray();
                lengths = lengthsList.ToArray();
    
                if (chunks.Length > 0) 
                    return true;
                else 
                    return false;
            }
    
  • 相关阅读:
    Codeforces 22E(图论)
    Codeforces Educational Round 23
    bzoj1444 有趣的游戏(AC自动机+概率dp)
    AtCoder Grand Contest 012 D Colorful Balls
    计蒜客15430 XOR Queries(Trie处理位运算问题)
    AtCoder Grand Contest 012 B Splatter Painting(记忆化搜索)
    Codeforces 799E(贪心)
    Codeforces Round #414
    Codeforces Educational Round 21
    LOJ10078
  • 原文地址:https://www.cnblogs.com/onecrazystone/p/9935695.html
Copyright © 2011-2022 走看看