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

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

Source

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<deque>
#include<iomanip>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<fstream>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAXN 100004
#define L 31
#define INF 1000000009
#define eps 0.00000001
/*
尺取
*/
int a[MAXN], n, s;
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
scanf("%d%d", &n, &s);
for (int i = ; i < n; i++)
scanf("%d", &a[i]);
int l = ,sum = ,ans = INF;
for (int r = ; r < n; r++)
{
sum += a[r];
while (sum >= s)
{
sum -= a[l];
ans = min(r - l + , ans);
l++;
}
}
if (ans != INF)
printf("%d\n", ans);
else
printf("0\n");
}
}

POJ 3061 Subsequence 尺取的更多相关文章

  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 Subsequence 尺取法,一个屌屌的O(n)算法

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

  5. POJ 3061 Subsequence ( 二分 || 尺取法 )

    题意 : 找出给定序列长度最小的子序列,子序列的和要求满足大于或者等于 S,如果存在则输出最小长度.否则输出 0(序列的元素都是大于 0 小于10000) 分析 : 有关子序列和的问题,都可以考虑采用 ...

  6. poj 3061 Subsequence

    题目连接 http://poj.org/problem?id=3061 Subsequence Description A sequence of N positive integers (10 &l ...

  7. POJ3061 Subsequence 尺取or二分

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

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

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

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

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

随机推荐

  1. [Swift通天遁地]三、手势与图表-(13)制作美观简介的滚动图表:折线图表、面积图表、柱形图表、散点图表

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  2. window.showModalDialog的问题

    通过window.showModalDialog的方式弹出B页面,总报“拒绝访问”的错误,将站点添加到受信任站点可以解决这个问题

  3. 1、Xamarin 环境准备

    一.安装环境 1.安装VS2017 2.安装Xamarin扩展包 3.安装NDK 工具栏中,一个为AVD(模拟器管理)一个为NDK(管理Andoid SDK) 3.1 先打开NDK,在Tools\Op ...

  4. mysql和java的时间对应关系

    引用:http://blog.csdn.net/xinghuo0007/article/details/51500923 MySQL(版本:5.1.50)的时间日期类型如下: datetime 8by ...

  5. 安卓发送图片文字,java后台接收

    安卓使用retrofit2 和rxjava2 url: @Multipart @POST(UrlTools.STORYUPLOAD) Observable<Result> saveRepo ...

  6. [Windows Server 2008] IIS自带FTP配置方法

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:IIS自带FT ...

  7. 7、scala面向对象编程之类

    1.  定义一个简单的类 2.getter与setter 3.自定义getter与setter方法 4.仅暴露field的getter方法 5.private[this]的使用 6.Java风格的ge ...

  8. C# 处理URL地址

    calendarset.do?start=1548518400&end=1552147200&_=1546421856958calendarset.do?start=155093760 ...

  9. 5.21leetcode练习

    目录 两数之和 题目 答案 整数反转 题目 思路及答案 回文数 题目 思路及答案 希望每天进步一点点 两数之和 题目 新手司机上路,光荣翻车,没想出来.借了别人的答案,自行领会 答案 整数反转 题目 ...

  10. python 模块学习——time模块

    Python语言中与时间有关的模块主要是:time,datetime,calendar time模块中的大多数函数是调用了所在平台C library的同名函数, 所以要特别注意有些函数是平台相关的,可 ...