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 785D Anton and School
    CodeForces 785C Anton and Fairy Tale
    CodeForces 785B Anton and Classes
    CodeForces 785A Anton and Polyhedrons
    爱奇艺全国高校算法大赛初赛C
    爱奇艺全国高校算法大赛初赛B
    爱奇艺全国高校算法大赛初赛A
    EOJ 3265 七巧板
    EOJ 3256 拼音魔法
    EOJ 3262 黑心啤酒厂
  • 原文地址:https://www.cnblogs.com/onecrazystone/p/9935695.html
Copyright © 2011-2022 走看看