【POJ】3061
来源:互联网 发布:611资源网 新域名在线 编辑:程序博客网 时间:2024/06/05 16:52
http://poj.org/problem?id=3061
给定长度n的数列,整数S,求和不小于S的连续子序列的长度的最小值。
尺取法例题。
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <queue>#include <algorithm>using namespace std;int t;int n,S;int a[100005];int sum[100005];int main(){ cin >> t; while (t--){ cin >> n >> S; for (int i=0;i<n;i++){ cin >> a[i]; } int ans=n+1; int s=0,t=0,sum=0; while (1){ while (t<n&&sum<S){ sum+=a[t++]; } if (sum<S) break; ans=min(ans,t-s); sum-=a[s++]; } if (ans>n) ans=0; cout << ans << endl; }}
阅读全文
0 0
- poj 3061
- poj 3061
- poj 3061
- poj-3061
- POJ 3061
- poj 3061
- poj 3061
- POJ----3061
- poj 3061
- 【POJ】3061
- poj 3061
- POJ 3061
- 【poj】 3061
- 尺取法专题 POJ 3061 POJ 3320 POJ 2566
- poj 3061 Subsequence
- poj 3061(高效枚举)
- POJ-3061-Subsequence
- POJ - 3061 Subsequence
- 关于产品经理
- like查询如何有索引效果
- 二进制位运算
- LeetCode 65. Valid Number
- 最长上升连续子序列
- 【POJ】3061
- CTF之利用sqlmap获取后台数据
- BZOJ3238: [Ahoi2013]差异(后缀数组)
- 使用SQLAlchemy操作数据库
- 前端初学学习进程VIII
- PHP设计模式
- 坚持#第190天~爬网站过完了
- 消息自定义
- MFC改变窗口标题“无标题—title”(title为程序名)