poj 3061 Subsequence(尺取)
来源:互联网 发布:苹果6韩版支持什么网络 编辑:程序博客网 时间:2024/05/16 18:08
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.
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.
For each the case the program has to print the result on separate line of the output file.if no answer, print 0.
210 155 1 3 5 10 7 4 9 2 85 111 2 3 4 5
23
#include <iostream>#include <algorithm>#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <string.h>#include <map>#include <set>#include <queue>#include <deque>#include <list>#include <bitset>#include <stack>#include <stdlib.h>#define lowbit(x) (x&-x)#define e exp(1.0)const int mod=1e9+7;const int inf=0x3f3f3f;//ios::sync_with_stdio(false);// auto start = clock();// cout << (clock() - start) / (double)CLOCKS_PER_SEC;typedef long long ll;typedef long long LL;using namespace std;/* _ooOoo_ o8888888o 88" . "88 (| -_- |) O\ = /O ____/`---'\____ .' \\| |// `. / \\||| : |||// \ / _||||| -:- |||||- \ | | \\\ - /// | | | \_| ''\---/'' | | \ .-\__ `-` ___/-. / ___`. .' /--.--\ `. . __ ."" '< `.___\_<|>_/___.' >'"". | | : `- \`.;`\ _ /`;.`/ - ` : | | \ \ `-. \_ __\ /__ _/ .-` / / ======`-.____`-.___\_____/___.-`____.-'====== `=---=' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pass System Test! */const int maxn=1e5+10;ll n,m;int a[maxn];ll sum;ll ans;int main(){ ios::sync_with_stdio(false); int T; cin>>T; while(T--) { cin>>n>>m; for(int i=1;i<=n;i++) cin>>a[i]; sum=0; ans=inf; int i=1,r=1; while(1) { while(r<=n && sum<m) sum+=a[r++]; if(sum<m) break; ans=min(ans,(ll)r-i); sum-=a[i++]; } ans==inf?cout<<"0"<<endl:cout<<ans<<endl; } return 0;}
阅读全文
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 (尺取法)
- [ACM] POJ 3061 Subsequence (尺取法)
- poj 3061 Subsequence(尺取法)
- POJ 3061 Subsequence(二分/尺取法)
- POJ-3061Subsequence(尺取法)
- POJ 3061 Subsequence(尺取法)
- POJ 3061 Subsequence(尺取法)
- POJ 3061 Subsequence(尺取法)
- POJ:3061 Subsequence(尺取法)
- POJ 3061 Subsequence(尺取法)
- POJ 3061 Subsequence (尺取法)
- 恶意样本分析手册-虚拟机检测篇(下)
- Ubuntu安装NVIDIA驱动补充
- java并发工具CountDownLatch的理解以及使用
- 2017.08.14工作日记
- 第二章 身份验证 (一) 登录、退出
- poj 3061 Subsequence(尺取)
- 归并排序
- 矩阵在游戏开发中的应用
- uC/OS-II系统学习笔记(2)——实时操作系统概念中篇
- Window Pains (POJ NO.1587 拓扑排序)
- grunt gruntfile.js详解
- Android 四大组件基础 Activity 生命周期
- 打印杨辉三角
- ThinkPHP5.0版本学习