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 ...
随机推荐
- LeetCode No.103,104,105
No.103 ZigzagLevelOrder 二叉树的锯齿形层次遍历 题目 给定一个二叉树,返回其节点值的锯齿形层次遍历.(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行). ...
- jsp 页面内容导出到Excel中
日常使用网络资源时经常需要把网页中的内容下载到本地,并且导出到Excel中,现在介绍一种非常简单的方式实现网络资源的下载.只需要讲jsp的最上面加上一句话 <% response.reset() ...
- python爬虫和数据分析、数据挖掘
一.python爬虫脑图: 二.python爬虫流程: 三.python数据分析简介 四.python数据预处理方法 五.python数据挖掘 六.数据探索基础
- P2967 [USACO09DEC]视频游戏的麻烦Video Game Troubles
冲刺阶段的首篇题解! 题目链接:P2967 [USACO09DEC]视频游戏的麻烦Video Game Troubles: 题目概述: 总共N个游戏平台,金额上限V元,给出每个游戏平台的价钱和其上游戏 ...
- highcharts 设置柱子之间的距离 柱子宽度
plotOption : { column : { // 设置每个柱自身的宽度 pointWidth : // x轴每个点只用一个柱,则这个属性设置的是相邻的两个点的柱之间的间距. // 如果x轴每个 ...
- 以elasticsearch-hadoop 向elasticsearch 导数,丢失数据的问题排查
实际这是很久之前的问题了,当时没时间记录 这里简单回顾 项目基于 数据架构不方便说太细,最精简的 somedata-> [kafka]->spark-stream->elastics ...
- crm项目-权限组件
############### 表结构分析 ################ """ 表结构设计: 1,四张表 用户表,userinfo,这个表本身不会被创 ...
- [LC] 165. Compare Version Numbers
Compare two version numbers version1 and version2.If version1 > version2 return 1; if version1 &l ...
- spring security梳理
核心服务:AuthenticationManager,UserDetailsService和AccessDecisionManager The AuthenticationManager, Provi ...
- DOCKER中centos7的中文支持
直接编写看下能否改变成识别中文字体 写到你的~/.bashrc里吧,然后重启终端(我写的是英文的啊,改成你要的) export LC_ALL=en_US.UTF-8 export LANGUAGE=e ...