UVA 11059(暴力)

[UVA 11059](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem =2000)
题意:输入n个元素组成的序列S,你需要找出一个乘积最大的连续子序列。如果这个最大的乘积不是正数,应输出0(表示无解)。1<=n<=18,-10<=Si<=10。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+10;
const ll inf = 0x3f3f3f3f;
int n;
ll maxx;
ll s[N];
int main(){
    #ifdef ONLINE_JUDGE
    #else
        freopen("in.txt", "r", stdin);
    #endif // ONLINE_JUDGE
    int iCase = 1;
    while(~scanf("%d", &n)){
        for(int i = 1; i <= n; i++){
            scanf("%lld", &s[i]);
        }
        maxx = -inf;
        for(int i = 1; i <= n; i++){
            ll sum = 1;
            for(int j = i; j <= n; j++){
                sum *= s[j];
                if(maxx < sum){
                    maxx = sum;
                }
            }
        }
        printf("Case #%d: The maximum product is ", iCase++);
        if(maxx < 0)
            printf("0");
        else
            printf("%lld", maxx);
        printf(".\n\n");
    }

    return 0;
}

posted on 2019-01-04 16:30  坤sir  阅读(133)  评论(0编辑  收藏  举报

导航