POJ 3061 Subsequence
2016-04-13 16:44
246 查看
尺取法。
#include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<queue> #include<algorithm> using namespace std; const int maxn=100000+10; int n; long long k,sum; long long a[maxn]; int ans,l,r; int main() { int T; scanf("%d",&T); while(T--) { scanf("%d%lld",&n,&k); for(int i=1; i<=n; i++) scanf("%lld",&a[i]); ans=999999999,l=r=1,sum=a[1]; while(1) { if(sum<k) { if(r==n) break; r++; sum=sum+a[r]; } else { ans=min(ans,r-l+1); sum=sum-a[l]; l++; } } if(ans==999999999) ans=0; printf("%d\n",ans); } return 0; }
相关文章推荐
- Reveal逆向工程:分析任意iOS应用的UI界面
- Xcode使用介绍之五:初识UI控件
- easyUI动态columns
- String , StringBuffer, StringBuilder的区别
- Xcode使用介绍之二:创建UI界面+连线
- 错误:-[UIKBBlurredKeyView candidateList]: unrecognized selector sent to instance
- Reason: no suitable image found
- APUE------信号
- Code Sign error: No matching provisioning profile found: Your build settings specify a provisioning
- Android 设置系统SystemUI 顶部StatusBar状态栏透明一体化
- CodeForces 163A Substring and Subsequence(DP)
- Uestc ABCDE 1037
- StringBuilder和stringBuffer的区别
- [LeetCode]Longest Increasing Subsequence
- -[UIWindow endDisablingInterfaceAutorotationAnimated:]
- 期望+DP ZOJ 3929 Deque and Balls
- UITableView官方文档翻译
- 175.Which two statements are true regarding savepoints? (Choose two.)
- 可展开的UITableViewCell
- hue安装