Subsequence POJ - 3061
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 22040 | Accepted: 9404 |
Description
Input
Output
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<cstdlib>
#include<sstream>
#include<cstring>
#include<string>
#include<vector>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<cmath>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
#define MAX_N 1000005
#define gcd(a,b) __gcd(a,b)
#define mem(a,x) memset(a,x,sizeof(a))
#define mid(a,b) a+b/2
#define stol(a) atoi(a.c_str())//string to long
int temp[MAX_N];
int main(){
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("D:\\in.txt","r",stdin);
// freopen("D:\\out.txt","w",stdout);
// #else
// #endif
int T;
scanf("%d",&T);
int N,S;
while(T--){
scanf("%d%d",&N,&S);
for(int i = ; i < N; i++)
scanf("%d",&temp[i]);
int sum = ;
queue<int> que;
int res = inf;
for(int i = ; i < N; i++){
que.push(temp[i]);
sum += temp[i];
while(sum >= S){
res = min(res,(int)que.size());
sum -= que.front();
que.pop();
}
}
if(res!=inf)
printf("%d\n",res);
else
printf("0\n");
}
return ;
}
Subsequence POJ - 3061的更多相关文章
- Subsequence poj 3061 二分(nlog n)或尺取法(n)
Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9236 Accepted: 3701 Descr ...
- Greedy:Subsequence(POJ 3061)
和最短序列 题目大意:找出一个序列中比至少和S相等的最短子序列(连续的) 本来这道题可以二分法来做复杂度O(NlogN),也可以用一个类似于游标卡尺的方法O(N)来做 先来讲游标卡尺法: 因为子序 ...
- poj 3061 Subsequence
题目连接 http://poj.org/problem?id=3061 Subsequence Description A sequence of N positive integers (10 &l ...
- POJ - 3061 Subsequence(连续子序列和>=s的最短子序列长度)
Description A sequence of N positive integers (10 < N < 100 000), each of them less than or eq ...
- POJ 3061 Subsequence(Two Pointers)
[题目链接] http://poj.org/problem?id=3061 [题目大意] 给出S和一个长度为n的数列,问最短大于等于S的子区间的长度. [题解] 利用双指针获取每一个恰好大于等于S的子 ...
- POJ 3061 Subsequence 二分或者尺取法
http://poj.org/problem?id=3061 题目大意: 给定长度为n的整列整数a[0],a[1],--a[n-1],以及整数S,求出总和不小于S的连续子序列的长度的最小值. 思路: ...
- poj 3061 Subsequence 二分 前缀和 双指针
地址 http://poj.org/problem?id=3061 解法1 使用双指针 由于序列是连续正数 使用l r 表示选择的子序列的起始 每当和小于要求的时候 我们向右侧扩展 增大序列和 每当和 ...
- POJ 3061 Subsequence(尺取法)
题目链接: 传送门 Subsequence Time Limit: 1000MS Memory Limit: 65536K 题目描述 给定长度为n的数列整数以及整数S.求出总和不小于S的连续子 ...
- Poj 3061 Subsequence(二分+前缀和)
Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12333 Accepted: 5178 Descript ...
随机推荐
- plsql中文显示问号
1. select userenv('language') from dual 2. 复制查询的值配置系统环境变量 NLS_LANG=AMERICAN_AMERICA.ZHS16GBK 3.配置系统环 ...
- Flask的Jinja2模版过滤器
Jinja2模版过滤器 过滤器是通过管道符号(|)进行使用的,例如:{{ name|length }},将返回name的长度.过滤器相当于是一个函数,把当前的变量传入到过滤器中,然后过滤器根据自己的功 ...
- cannot be found on object of type xx.CacheExpressionRootObject
0 环境 系统环境:win10 编辑器:IDEA 1 前言->环境搭建 1-1 pom依赖 <?xml version="1.0" encoding="UTF ...
- 如何回收VCSA 6自带的vPostgres数据库空间
最近有学生连续反应由于VCSA磁盘空间满了,导致服务无法正常启动,寻求压缩数据库空间的问题.首先说下,VCSA的数据库是没办法图形界面管理的, 它的内置vPostgres数据库的管理只能通过命令行来完 ...
- ionic2踩坑之订阅发布模式的实现
原文地址:http://www.cnblogs.com/eccainiao/p/6429536.html 转载请说明. 在ionic2中实现订阅发布模式,需要用到Events. Events下面有三个 ...
- mysql 存储过程与存储函数
第一节:存储过程和函数的引入 存储过程和函数是在数据库中定义一些SQL 语句的集合,然后直接调用这些存储过程和函数来执行已经定义好的SQL 语句.存储过程和函数可以避免开发人员重复的编写相同的SQL ...
- openpyxl操作excel表格
1.openpyxl 只支持打开.xlsx格式,其他excel类库基本也是 2.不能这里的工作面板直接右键新建表格,必须到文件夹下面去新建,可以把在别的目录新建的表格直接复制到当前目录下 3.从表格中 ...
- Maven基本概念和操作
最近在学Java,找来一个开源项目练手,它是用 Spring Boot 搭建的框架,于是去学 Spring Boot,然而 Spring Boot 需要有 Spring 框架和 Maven 的使用经验 ...
- liubo.im
elite-lessons (37) --> 1025 精英水平的道歉 29/10/2016 1027 听大脑说话.给大脑编程 27/10/2016 1022 美国两党政治为什么越来越极化? 2 ...
- 查漏补缺:QT入门
1.什么世QT Qt是一个跨平台的C++图形用户界面应用程序框架,为应用程序开发者提供建立艺术级图形界面所需的所有功能.它是完全面向对象的,容易扩展,并且允许真正的组建编程. 2.支持平台 Windo ...