poj 3061 时间复杂度为O(n)
来源:互联网 发布:淘宝智能二手手机 编辑:程序博客网 时间:2024/05/17 12:02
//尺取法,复杂度为O(n) #include <iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;const int maxn=100000+5;int a[maxn];int main(){ int t; scanf("%d",&t); while(t--) { int n,s; scanf("%d%d",&n,&s); for(int i=0;i<n;i++) scanf("%d",&a[i]); int res=n+1; int f=0,e=0,sum=0; //f为上界,e为下界 for(;;) { while(e<n&&sum<s) sum+=a[e++]; if(sum<s) break; res=min(res,e-f); sum-=a[f++]; } if(res>n) res=0; cout<<res<<endl; } return 0;}
阅读全文
0 0
- poj 3061 时间复杂度为O(n)
- poj 2127 时间复杂度为O(m*n)
- 时间复杂度为O(n),空间复杂度为O(1)
- 时间复杂度为O(n)的排序
- 时间复杂度为O(n)的排序
- 1~n无序数组时间复杂度为O(n)排序
- 1~n无序数组时间复杂度为O(n)排序
- 排序的时间复杂度为O(n),空间复杂度为O(1)
- 时间复杂度为O(N),空间复杂度为O(1)的排序算法
- 时间复杂度为O(n+t)的排序
- 时间复杂度为O(n)的排序算法
- 时间复杂度为O(n)的排序算法--计数算法
- 字符串左旋满足时间复杂度为O(n)
- 求一个数组的中位数时间复杂度为O(n)
- 实现排序算法,时间复杂度为O(n)
- 时间复杂度为O(m*n)最长公共子串
- 面试9:时间复杂度为O(n)的排序算法
- 平均时间复杂度为O(n)的选择算法
- Java中的异常
- python3.5函数的参数样式种类以及装饰器
- opengles2.0 headfirst sample triangle
- C# MVC实现导出到EXCEL
- HTML5音频和视频处理
- poj 3061 时间复杂度为O(n)
- 求Sn = a + aa + aaa +... + a.....a 的值,其中a为数字,n为最后一个数字中a的位数,a和n由键盘输入。
- ArrayList的优缺点
- Java:eclipse调试
- classfile.ClassFormatException
- 第六单元
- Reflection2017.10.9
- 基于OpenCV的视频图像组态 (3):常见PPT动画1
- C# ASCII与字符串间相互转换