• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            ACM PKU 3061 Subsequence

            http://acm.pku.edu.cn/JudgeOnline/problem?id=3061 


            Subsequence 
            Time Limit:1000MS  Memory Limit:65536K 
            Total Submit:2626 Accepted:833 
            Description A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, and a positive integer S (S < 100 000 000) are given. Write a program to find the minimal length of the subsequence of consecutive elements of the sequence, the sum of which is greater than or equal to S. 
            Input 
            The first line is the number of test cases. For each test case the program has to read the numbers N and S, separated by an interval, from the first line. The numbers of the sequence are given in the second line of the test case, separated by intervals. The input will finish with the end of file. 
            Output 
            For each the case the program has to print the result on separate line of the output file.if no answer, print 0. 
            Sample Input 
            210 155 1 3 5 10 7 4 9 2 85 111 2 3 4 5 


            Sample Output 
            23 


            Source 
            Southeastern Europe 2006 

            不知道為什么這道題在Discuss里被罵得體無完膚 
            http://acm.pku.edu.cn/JudgeOnline/bbs?problem_id=3061 


            注意細(xì)節(jié)很重要啊!我至少調(diào)試了兩個小時才AC!! 

            Source
            Problem Id:3061  User Id:lnmm 
            Memory:464K  Time:31MS 
            Language:C++  Result:Accepted 
            Source 
             1#include"stdio.h" 
             2int a[100010]; 
             3void main() 
             4
             5long sum,N,S,min; 
             6long left,right,r;  //left 左游標(biāo),right 右游標(biāo), r向右擴展游標(biāo) 
             7int T,i; 
             8scanf("%d",&T); 
             9       for(i=1;i<=T;i++
            10    
            11  sum=0
            12        scanf("%ld%ld",&N,&S); 
            13        for(r=1;r<=N;r++
            14  
            15   scanf("%ld",&a[r]); 
            16   sum+=a[r]; 
            17  }
             
            18   min=100001
            19  if(sum<S) 
            20  
            21   min=0
            22  }
             
            23         sum=0
            24         right=0
            25    a[0]=0
            26   //初始化完成 
            27
            28
            29  for(left=1;left<=N;left++
            30  
            31   sum=sum-a[left-1]; 
            32   if(sum >= S)   
            33            {     
            34                if(right-left+1 < min  ) min=right-left+1;   
            35                continue;   
            36                }
               
            37             for(r=right+1;r<=N;r++
            38    
            39     sum=sum+a[r]; 
            40     if(sum>=S) 
            41     {   if(r-left+1 < min) min=r-left+1
            42                       right=r; 
            43      break
            44     }
             
            45    }
             
            46  }
             
            47
            48  printf("%d\n",min);   
            49    }
             
            50
            51return ; 
            52}

            posted on 2007-09-14 02:02 流牛ζ木馬 閱讀(676) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            <2007年9月>
            2627282930311
            2345678
            9101112131415
            16171819202122
            23242526272829
            30123456

            導(dǎo)航

            統(tǒng)計

            公告

            MY Email/MSN :mars1021@163.com QQ : 27402040 流牛ζ木馬

            常用鏈接

            留言簿(6)

            隨筆檔案

            相冊

            搜索

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

            久久综合中文字幕| AV狠狠色丁香婷婷综合久久 | 亚洲国产日韩欧美久久| 久久99精品国产一区二区三区| 午夜精品久久久久久毛片| 一本一本久久A久久综合精品 | 久久精品一区二区三区AV| 久久精品国产一区二区| 久久精品国产亚洲一区二区三区| 色综合久久中文色婷婷| 久久精品不卡| 一级a性色生活片久久无| 久久精品国产亚洲AV忘忧草18| 久久强奷乱码老熟女网站| 国内精品久久久久影院薰衣草 | 国产精品久久久久乳精品爆| 青草影院天堂男人久久| 久久成人18免费网站| 性高朝久久久久久久久久| 亚洲午夜久久久久妓女影院| 久久精品亚洲日本波多野结衣 | 久久精品中文字幕无码绿巨人| 久久久一本精品99久久精品88| 97超级碰碰碰久久久久| 99久久精品免费看国产免费| 久久婷婷五月综合97色直播| 99精品国产免费久久久久久下载| 久久亚洲私人国产精品| 伊人久久大香线焦综合四虎| 香蕉久久久久久狠狠色| 91久久九九无码成人网站 | 亚洲精品WWW久久久久久| 久久精品卫校国产小美女| www性久久久com| 久久婷婷五月综合国产尤物app| 久久久久AV综合网成人| 久久精品无码av| 国产∨亚洲V天堂无码久久久 | 久久精品国产99国产电影网| 2020久久精品亚洲热综合一本| 国产91久久精品一区二区|