码迷,mamicode.com
首页 > 其他好文 > 详细

poj 3061

时间:2017-05-09 23:13:04      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:i++   color   stream   clu   ios   max   break   const   poj   

尺取法板子

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=100000+10;
int a[maxn];
int t,n,S;
int chiqu()
{   int t=0,s=0,sum=0;
  int ans=n+1;
    while(1)
    {
        while(t<n&&sum<S)
        {
            sum+=a[t++];
        }
        if(sum<S)  break;
        ans=min(ans,t-s);
        sum-=a[s++];
    }
    if(ans>n) ans=0;
    return ans;
}
int main()
{
   scanf("%d",&t);
   while(t--)
   {
       scanf("%d%d",&n,&S);
       for(int i=0;i<n;i++)
           scanf("%d",&a[i]);
         printf("%d\n",chiqu());
   }
    return 0;
}

 

poj 3061

标签:i++   color   stream   clu   ios   max   break   const   poj   

原文地址:http://www.cnblogs.com/Wangwanxiang/p/6833036.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!