【poj】 3061
来源:互联网 发布:淘宝销售数据查询 编辑:程序博客网 时间:2024/06/05 15:33
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
最短序列
代码:
#include<cstdio>#include<algorithm>using namespace std;int main(){int n,s,t,a[100000+5];scanf("%d",&t);while(t--){scanf("%d %d",&n,&s);for(int i=0;i<n;i++)scanf("%d",&a[i]);int sum=0,j=0,num=0;int ans=n+1;while(1){while((j<n)&&(sum<s)){sum+=a[j++];}if(sum<s)break;ans=min(ans,j-num);sum-=a[num];num++;}if(ans>n) printf("0\n");else printf("%d\n",ans);}return 0; }
阅读全文
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
- mySQL批量插入删除操作
- SpringMVC中定时任务配置
- windows稀疏文件
- !important的用法
- 详解操作系统中断
- 【poj】 3061
- python高效编程技巧10(如何读写json)
- SQL—排名函数的应用
- mysql安装
- Java-class1&2
- ios 屏幕截图
- 在开机启动脚本/etc/init.d/rcS中添加自己的应用程序
- Solr卸载、加载索引数据
- Java批量插入数据