算法问题:
某物质每分钟有个实验监测值t(i),每天共有1440个测值序列t(1)、t(2)、……t(1440)。算法条件:
1、如果某天从第i个测值开始,其后有n个连续测值为递增序列,则计算出dTmax=t(i+n)-t(i),并记录下序列号i、i+n;
2、请输出所有满足条件1的dtmax、i、i+n。
我的代码比较繁,输出结果与图形比对,不能完全吻合,在这里向高手请教简明算法,谢谢!

解决方案 »

  1.   

    '就给你一算法的思路,我没试调,具体细节你还要试调,你参考就好。
    '暂时存放dtmax、i、n三个数据
    Dim tempI As Double  '
    Dim tempN As Double
    Dim tempDtmax As Double'循环计数
    Dim i As Long'用来检查递增的计数
    Dim j As Long
    For i = 1 To 1440
         j = i
         tempI = i  '
         tempDtmax = 0
             
             '判断递增.
            Do While t(j + 1) > t(j)
               tempN = j + 1
               tempDtmax = t(j + 1) - t(j)
               j = j + 1
               i = j '注意,把for循环中的计数i,跳到递增结束的位置.
            Loop
          
          
         If tempDtmax > 0 Then ' 如果tempDtmax>0说明出现递增情况
                
            '在这里把tempI,tempN,tempDmax,存到专门存放它们的数组即可,
            '……………………………… '
             '代码省略
        End If       
    Next
                 
              
      

  2.   

    '就给你一算法的思路,我没试调,具体细节你还要试调,你参考就好。 
    '暂时存放dtmax、i、n三个数据 
    Dim   tempI   As   Double     ' 
    Dim   tempN   As   Double 
    Dim   tempDtmax   As   Double '循环计数 
    Dim   i   As   Long '用来检查递增的计数 
    Dim   j   As   Long 
    For   i   =   1   To   1440 
              j   =   i 
              tempI   =   i     ' 
              tempDtmax   =   0 
                      
                      '判断递增. 
                    Do   While   t(j   +   1)   >   t(j) 
                          tempN   =   j-tempI
                          tempDtmax   =   t(j   +   1)   -   t(j) 
                          j   =   j   +   1 
                          i   =   j   '注意,把for循环中的计数i,跳到递增结束的位置. 
                    Loop 
                
                
              If   tempDtmax   >   0   Then   '   如果tempDtmax> 0说明出现递增情况 
                            
                    '在这里把tempI,tempN,tempDmax,存到专门存放它们的数组即可, 
                    '………………………………   ' 
                      '代码省略 
            End   If               
    Next