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 ...
随机推荐
- 算法笔记4.3递归 问题 A: 吃糖果
问题 A: 吃糖果 题目描述 名名的妈妈从外地出差回来,带了一盒好吃又精美的巧克力给名名(盒内共有 N 块巧克力,20 > N >0). 妈妈告诉名名每天可以吃一块或者两块巧克力. 假设名 ...
- python3下scrapy爬虫(第十四卷:scrapy+scrapy_redis+scrapyd打造分布式爬虫之执行)
现在我们现在一个分机上引入一个SCRAPY的爬虫项目,要求数据存储在MONGODB中 现在我们需要在SETTING.PY设置我们的爬虫文件 再添加PIPELINE 注释掉的原因是爬虫执行完后,和本地存 ...
- 通俗易懂JSONP讲解
原文地址:http://www.cnblogs.com/dowinning/archive/2012/04/19/json-jsonp-jquery.html JSON的格式或者叫规则: JSON能够 ...
- 用Microsoft Chart Controls(MSChart)实现曲线图,并支持拖动放大到秒
Microsoft Chart Controls(简称MSChart)控件,给图形统计和报表图形显示提供了很好的解决办法,同时支持Web和WinForm两种方式. MSChart 在.NET 4.0自 ...
- Sampling Error|Sampling mean|population mean
7.1 Sampling Error; the Need for Sampling Distributions 样本均值的三种表达: Sampling distribution of the samp ...
- 提前窥测奥斯卡颁奖信封中的谜底 ——Rothschild预测2014奥斯卡花落谁家
--Rothschild预测2014奥斯卡花落谁家" title="提前窥测奥斯卡颁奖信封中的谜底 --Rothschild预测2014奥斯卡花落谁家"> 编者 ...
- deeplearning.ai 构建机器学习项目 Week 2 机器学习策略 II
1. 误差分析(Error analysis) 误差分析的目的是找到不同误差源的比重,从而指引我们接下来往哪个方向努力改进.NG建议手工统计随机100个错误的误差源,比如对于猫分类器,错误的照片可能是 ...
- Serializable中的serialVersionUID是必须的吗
不写serialVersionUID就没有吗 即使不写, jdk反序列化时也会自动检查这个id, 反编译.class文件你也看不到这个值 rpc反序列化 如果使用jdk的方式, 这个必须配置 如果使用 ...
- SpringBoot连接Oracle报错,找不到驱动类,application.properties文件中驱动类路径为红色
pom.xml文件: <!-- oracle odbc --> <dependency> <groupId>com.oracle</groupId> & ...
- reduced penetrance|COPE-PCG
生物医学大数据 Case study 由Human genome project提出之后,提出的精准医学.它的初衷是将数据standard后easy应用,我国重要重在疾病预警和疗效评价. 在疾病预警上 ...