Advertisement

UVa 1619( feel good )

阅读量:

题意:
寻找一个连续的子序列,使得 e 等于该子序列的和乘以该子序列中的最小值,求出使 e 达到最大值的区间以及对应的 e 值

分析:
可采用单调递增栈的方式进行处理,并注意数据类型的选取应使用 LL
基于单调递增栈的算法时间复杂度为 O(n)

代码:

复制代码
    #include<bits/stdc++.h>
    #define LL long long
    #define ms(s) memset(s, 0, sizeof(s))
    using namespace std;
    const int maxn = 1e5 + 10;
    LL a[maxn];
    LL sum[maxn];
    
    //题目有误,当最大值相同时不是输出任意区间都可以的
    //应该是输出最短的区间,长度相同时输出左端点最小的区间
    
    int main() {
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    int kase = 0;
    while(cin >> n && n)

全部评论 (0)

还没有任何评论哟~