标签:using lse 没有 https code return sum class tps
https://vjudge.net/problem/POJ-3061
尺取发,s和t不断推进的算法。因为每一轮s都推进1所以复杂度为O(n)
1 #include<iostream> 2 #include<cstdio> 3 #include<queue> 4 #include<cstring> 5 #include<algorithm> 6 #include<cmath> 7 #include<stack> 8 #define lson l, m, rt<<1 9 #define rson m+1, r, rt<<1|1 10 #define INF 0x3f3f3f3f 11 typedef unsigned long long ll; 12 using namespace std; 13 int a[100010]; 14 int main() 15 { 16 int kase, n, m, S; 17 cin >> kase; 18 while(kase--){ 19 cin >> n >> S; 20 for(int i = 0; i < n; i++){ 21 cin >> a[i]; 22 } 23 int s=0, t=0, sum=0, ans = INF;//尺取法,开始s和结尾t不断推进 24 while(1){ 25 while(t < n&&sum < S){ 26 sum += a[t++]; 27 } 28 if(sum<S) break;//也即t>=n退出 29 ans = min(ans, t-s); 30 sum -= a[s++];//s推进,sum修改 31 } 32 if(ans == INF) //没有符合要求的 33 cout << "0" << endl; 34 else cout << ans << endl; 35 } 36 return 0; 37 }
标签:using lse 没有 https code return sum class tps
原文地址:https://www.cnblogs.com/Surprisezang/p/9017818.html