poj-3061
来源:互联网 发布:自贡网络电视台 编辑:程序博客网 时间:2024/06/06 03:14
首先计算出在前 i 项的和 然后快速枚举 计算最小值 :
#include <stdio.h>#include <math.h>#include <stdlib.h>#include <algorithm>#include <queue>#include <iostream>using namespace std;int a[100100];int sum[100100];int main (){ int t; cin>>t; while (t--) { int n,m; cin>>n>>m; for (int i=1;i<=n;i++) cin>>a[i]; sum[0]= 0; for (int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i]; int ans = n; int ok =1 ,ko; if ( sum[n] < m ) ok = 0; int i = 1; for (int j=1;j<=n;j++) { ko=0; while (sum [j] - sum [i] >= m) { i++; ko=1; } if (ko) ans = min (ans , j - i + 1 ); } if (ok) printf("%d\n",ans); else printf ("0\n"); } 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
- MFC下动态添加控件
- Eclipse 安装SVN插件
- EA建模-绘制状态图
- 【Error】JavaWeb: 严重: Failed to initialize end point associated with ProtocolHandler ["http-bio-8080"]
- 2、MyBatis.NET学习笔记-之CodeSmith使用
- poj-3061
- 关于android:configChanges="keyboardHidden|orientation"
- 站在巨人的肩膀上,C++开源库大全
- 谈谈测试用例的分类
- 黑马程序员--------Java基础知识总结(二)
- Linux文本过滤命令grep|awk|sed小结
- HDU 4081 Qin Shi Huang's National Road System (Prim, 次小生成树)
- 枚举上个月的日期
- Magento Event/Observer的用法//// shell运行脚本