UVALive
来源:互联网 发布:淘宝客服岗位说明 编辑:程序博客网 时间:2024/06/11 18:31
尺取法
O(n)复杂度
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<vector>#include<set>#include<stack>#include<algorithm>using namespace std;typedef long long ll;typedef pair<ll, ll> P;const int maxn = 100000 + 7, INF = 0x3f3f3f3f, mod = 1e9+7;int n, m, l, r;int a[maxn];void solve() { l = r = -1; int sum = 0, ans = INF; //cout << ans << " === " << endl; while(r < n) { while(r < n && sum < m) { r++; sum += a[r]; } if(r >= n) break; //cout << l << " == " << r << endl; while(l < r && sum >= m) { ans = min(ans, min(r, n) - l); l++; sum -= a[l]; } } if(ans == INF) ans = 0; cout << ans << endl;}int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); while(scanf("%d%d", &n, &m) != EOF) { for(int i = 0; i < n; ++i) scanf("%d", &a[i]); solve(); } return 0;}
阅读全文
1 0
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- 网络流 增广路 入门很好的文章
- Farm Irrigation HDU
- http,socket,tcp/ip 网络传输与通讯知识总结
- K9F1G08U0E-SCB0 兼容的芯片
- POJ 3311 Hie with the Pie (Floyd+状压DP)
- UVALive
- The processing instruction target matching "[xX][mM][lL]" is not allowed.错误
- Cascading——针对Hadoop MapReduce的数据处理API
- 【Idea】——非Maven项目导入jar包
- 并查集知识图解
- mapreduce实现ItemCF——基于物品的协同过滤
- leetcode--Trapping Rain Water
- 多线程并发
- 如何在window下搭建tensorflow开发环境