POJ 3061 Subsequence
来源:互联网 发布:淘宝拍视频用什么软件 编辑:程序博客网 时间:2024/06/05 09:35
Subsequence
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 16812 Accepted: 7141
Description
A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, and a positive integer S (S < 100 000 000) are given. Write a program to find the minimal length of the subsequence of consecutive elements of the sequence, the sum of which is greater than or equal to S.
Input
The first line is the number of test cases. For each test case the program has to read the numbers N and S, separated by an interval, from the first line. The numbers of the sequence are given in the second line of the test case, separated by intervals. The input will finish with the end of file.
Output
For each the case the program has to print the result on separate line of the output file.if no answer, print 0.
Sample Input
210 155 1 3 5 10 7 4 9 2 85 111 2 3 4 5
Sample Output
23
Source
Southeastern Europe 2006
题目大意:给你n个数字,再给你一个S,求大于S的连续子序列的最小长度
尺取法
#include<iostream>#include<algorithm>using namespace std;int num[100010];int main(){//freopen("in.txt","r",stdin);int t;cin>>t;while(t--){int n,s;cin>>n>>s;for(int i=0;i<n;i++) cin>>num[i];int i=0,j=0;int sum=0;int ans=n+1;while(true){while(j<n&&sum<s) sum+=num[j++];if(sum<s) break;ans=min(j-i,ans);sum-=num[i++];}if(ans>n) ans=0;cout<<ans<<endl;}}
阅读全文
0 0
- poj 3061 Subsequence
- POJ-3061-Subsequence
- POJ - 3061 Subsequence
- POJ:3061 Subsequence
- poj 3061 Subsequence
- poj 3061 Subsequence
- POJ 3061 Subsequence
- poj 3061 Subsequence
- poj 3061 Subsequence
- POJ 3061 Subsequence
- POJ 3061 Subsequence
- poj 3061 Subsequence
- poj 3061 Subsequence
- poj 3061 Subsequence
- POJ-3061 Subsequence
- poj 3061 Subsequence
- POJ 3061 Subsequence
- POJ 3061 Subsequence《《前加后去,,,》》
- 【makefile】一起写makefile(三)--Makefile书写规则
- 手撕Arm NEON 汇编 (引入)
- 论人生(1)
- HashSet和TreeSet的区别
- 最实用的10个重构小技巧排行榜,您都用过哪些呢?
- POJ 3061 Subsequence
- 登录注册mvp模式
- qqqqqqqqqqqq
- RecyclerView上拉刷新,下拉加载
- chrome插件开发
- springMVC上传,富文本上传和ftp服务器的配置
- 第三部分:Idea重构总结
- 给大家介绍一下,这是twitter的创始人@
- 需要有效的董事会