Subsequence
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 9050   Accepted: 3604

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

2
10 15
5 1 3 5 10 7 4 9 2 8
5 11
1 2 3 4 5

Sample Output

2
3
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 100001
const int inf=0x7fffffff; //无限大
int a[maxn];
int main()
{
int t;
cin>>t;
while(t--)
{
int n,s;
cin>>n>>s;
for(int i=;i<n;i++)
{
cin>>a[i];
}
ll sum=a[];
int st=,en=;
int minn=inf;
while(en!=n&&st<=en)
{
//cout<<st<<" "<<en<<" "<<sum<<endl;
if(sum>=s)
{
minn=min(minn,en-st+);
sum-=a[st];
st++;
}
if(sum<s)
{
en++;
sum+=a[en];
}
}
if(minn==inf)
cout<<""<<endl;
else
cout<<minn<<endl;
}
return ;
}

POJ 3061 Subsequence 尺取法,一个屌屌的O(n)算法的更多相关文章

  1. POJ 3061 Subsequence 尺取法

    转自博客:http://blog.chinaunix.net/uid-24922718-id-4848418.html 尺取法就是两个指针表示区间[l,r]的开始与结束 然后根据题目来将端点移动,是一 ...

  2. POJ 3061 Subsequence 尺取法 POJ 3320 Jessica's Reading Problem map+set+尺取法

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13955   Accepted: 5896 Desc ...

  3. POJ 3061 Subsequence(尺取法)

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18145   Accepted: 7751 Desc ...

  4. poj 3061 题解(尺取法|二分

    题意 $ T $ 组数据,每组数据给一个长度 $ N $ 的序列,要求一段连续的子序列的和大于 $ S $,问子序列最小长度为多少. 输入样例 2 10 15 5 1 3 5 10 7 4 9 2 8 ...

  5. POJ 3061 Subsequence 尺取

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14698   Accepted: 6205 Desc ...

  6. POJ 3061 Subsequence 二分或者尺取法

    http://poj.org/problem?id=3061 题目大意: 给定长度为n的整列整数a[0],a[1],--a[n-1],以及整数S,求出总和不小于S的连续子序列的长度的最小值. 思路: ...

  7. 题解报告:poj 3061 Subsequence(前缀+二分or尺取法)

    Description A sequence of N positive integers (10 < N < 100 000), each of them less than or eq ...

  8. POJ 3061 Subsequence【二分答案】||【尺取法】

    <题目链接> 题目大意: 给你一段长度为n的整数序列,并且给出一个整数S,问你这段序列中区间之和大于等于S的最短区间长度是多少. 解题分析:本题可以用二分答案做,先求出前缀和,然后枚举区间 ...

  9. POJ 3061 Subsequence ( 尺取法)

    题目链接 Description A sequence of N positive integers (10 < N < 100 000), each of them less than ...

随机推荐

  1. liunx系统top命令详解

    ps: 1.按1可以进行 CPU各个和总CPU汇总的切换2.cpu0是最关键的,总控管理各个CPU 3.默认情况下仅显示比较重要的 PID.USER.PR.NI.VIRT.RES.SHR.S.%CPU ...

  2. Apache HBase Performance Tuning 官文总结

    Apache HBase Performance Tuning RAM, RAM, RAM. 不要让HBase饿死. 请使用64位的平台 必须将swapping设定为0 使用本地硬件来完成hdfs的c ...

  3. Python 常用的内建函数

    内建函数 ​ Build-in Function,启动python解释器,输入dir(__builtins__), 可以看到很多python解释器启动后默认加载的属性和函数,这些函数称之为内建函数, ...

  4. ls和cd命令详解

    ls命令 命令功能: ​ 列出当前目录下或者指定目录下的所有文件和目录,ls是list的缩写. 命令语法: ls [选项][目录名 ] #注:[ ]中的内容为非必选项 命令选项: | 选项 | 含义 ...

  5. javascript本地缓存方案-- 存储对象和设置过期时间

    cz-storage 解决问题 1. 前端js使用localStorage的时候只能存字符串,不能存储对象 cz-storage 可以存储 object undefined number string ...

  6. ASP .Net Core系统部署到 CentOS7 64 具体方案

    .Net Core 部署到 CentOS7 64 位系统中的步骤 1.安装工具 1.apache 2..Net Core(dotnet-sdk-2.0) 3.Supervisor(进程管理工具,目的是 ...

  7. Python爬虫之HDU提交数据

    前一篇http://www.cnblogs.com/liyinggang/p/6094338.html 使用了爬虫爬取hdu 的代码,今天实现了将数据向hdu 提交的功能,接下来就是需要将两个功能合并 ...

  8. Linux下的堆伪造漏洞利用技术(new unlink)

    感觉markdown的文件格式看起来更清晰一些就写成附加的形式了.Download 更正:这种利用方式不叫House of Mind,是我搞混了.

  9. element-ui 2.7.2版本使用 表格展开行 功能遇到的奇葩问题?

    在使用 element-ui 2.7.2版本的时候报下面的错误: [Vue warn]: Error in callback for watcher "data": "E ...

  10. 一个带bash,带glibc,中国时区,非root用户可运行crond命令的基于alpine镜像的Dockerfile

    这个镜像现在说起来简单, 带bash(增加执行脚本的兼容性,带GLIBC,中国时区,非root用户可运行crond命令-安全) 但让我开始陷入时,真的让我有段时间有点爆了. 比如,将filebeat文 ...