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 ...
随机推荐
- 项目引入nacos 日志不显示问题
禁用nacos的日志即可解决 idea当中 添加vm options参数即可 -Dnacos.logging.default.config.enabled=false 打包后的启动命令 java - ...
- vue2.0学习之路由
下载vue-router: cnpm install vue-router --save router/main.js /*引入所需要的组件*/ import VueRouter from 'vue- ...
- Jmeter阶梯式压测
https://www.cnblogs.com/Zfc-Cjk/p/11639219.html 什么是阶梯式压测? 阶梯式压测,就是对系统的压力呈现阶梯性增加的过程,每个阶段压力值都要增加一个数量值, ...
- Xcode查看iOS崩溃与崩溃日志分析
一.造成崩溃的原因 1.代码中存在bug 2.Watchdog 超时机制 3.用户强制退出 4.低内存终止 5.其他违法系统规则的操作,大部分是内存问题 二.崩溃的类型 1.信号错误类 (1)EXC_ ...
- spring-mvc基于注解的配置
将配置文件修改为: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="htt ...
- ValidationUtil
package me.zhengjie.common.utils; import me.zhengjie.common.exception.BadRequestException; import ja ...
- 吴裕雄--天生自然 Hadoop大数据分布式处理:centos7修改系统时间、时区
cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 修改完后需要重启.
- deeplearning.ai 神经网络和深度学习 week1 深度学习概论
1. 预测房价.广告点击率:典型的神经网络,standard NN. 图像:卷积神经网络,CNN. 一维序列数据,如音频,翻译:循环神经网络,RNN. 无人驾驶,涉及到图像.雷达等更多的数据类型:混合 ...
- Centos7下常见命令
1: hostnamectl set-hostname oldgirl 设置主机名直接生效 2: hostname oldboy (暂时生效,重启后恢复原来主机名)
- volatile与Synchronized
摘自: https://blog.csdn.net/zxh476771756/article/details/78685581 一.JVM内存模型: JVM将内存组织为主内存和工作内存两个部分. 主内 ...