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. ARM Linux 3.x的设备树(Device Tree)【转】

    转自:http://blog.csdn.net/21cnbao/article/details/8457546 宋宝华 Barry Song <21cnbao@gmail.com> 1.  ...

  2. u-boot移植随笔(7):u-boot启动流程简图【转】

    转自:http://www.latelee.org/porting-uboot/u-boot-porting-bootstrap.html u-boot移植随笔:u-boot启动流程简图 画上面这张图 ...

  3. innobackupex 相关语法讲解【转】

    innobackupex 相关语法讲解 连接服务器 The database user used to connect to the server and its password are speci ...

  4. COM组件服务访问权限

    解决办法 :添加ASP.NET权限访问COM组件服务. IIS 5 上为 {MACHINE}\ASPNET IIS 6 和 IIS 7 上为网络服务:NETWORK SERVICE IIS 7.5 上 ...

  5. Java 并发--线程创建

    随着处理器的多核化,为提高处理器的资源利用率应用程序的并发变应运而生了.现在的操作系统是多任务操作系统,多线程是实现多任务的一种方式. 进程是指一个内存中运行的应用程序,每个进程都有自己独立的内存空间 ...

  6. mysqlbinlog的日志类型

    一.mysqlbinlog简介 binlog又叫二进制日志文件,它会将mysql中所有修改数据库数据的Query以二进制的形式记录到日志文件中,如:create,insert,drop,update等 ...

  7. UVA 10891 Game of Sum(区间DP(记忆化搜索))

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  8. RobotCraft 2017 第二届国际机器人学暑期学校 2nd Edition of International Robotics Summer School

    原文网址:http://www.ros.org/news/2017/02/2nd-edition-of-international-robotics-summer-school-robotcraft- ...

  9. Linux学习笔记:mv移动或文件重命名

    mv命令是move的缩写,可以用来移动文件或者将文件改名(move (rename) files),是Linux系统下常用的命令,经常用来备份文件或者目录. 语法:mv 源文件 目标文件 视mv命令中 ...

  10. Linux下的IPC机制

    Linux下的IPC机制 IPC(Inter-Process Communication)是多个进程之间相互沟通的一种方法.在linux下有多种进程间通信的方法. 共享内存 Linux内存共享有多种, ...