Hust oj 2116 Maximum continuous product(水题)

Maximum continuous product
Time Limit: 1000 MSMemory Limit: 32768 K
Total Submit: 119(40 users)Total Accepted: 38(33 users)Rating: Special Judge: No
Description

Wind and his GF(game friend) are playing a small game. They use the computer to randomly generated a number sequence which only include number 2,0 and -2. To be the winner,wind must 

have to find a continuous subsequence whose continuous product is maximum.

For example, we have a sequence blow:

2 2 0 -2 0 2 2 -2 -2 0

Among all of it's continuous subsequences, 2 2 -2 -2 own the maximum continuous product.

(2*2*(-2)*(-2) = 16 ,and 16 is the maximum continuous product)

You,wind's friend,can give him a hand.


Input

The first line is an integer T which is the Case number(T <= 200).

For each test case, there is an integer N indicating the length of the number sequence.(1<= N <= 10000)

The next line,there are N integers which only include 2,0 and -2.


Output

For each case,you have to output the case number first(Reference the sample).

If the answer is smaller than 0, you just need to output 0 as the answer.

If the answer's format is 2^x,you need to output the x as the answer.

Output the answer in one line.


Sample Input
2
2
-2 0
10
2 2 0 -2 0 2 2 -2 -2 0
Sample Output
Case #1: 0
Case #2: 4
 
题意有点坑,没明说可以在一段中截取一段计算乘积
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

const int maxn = 10005;
const int Inf = 0x3f3f3f;
int a[maxn];
int t,n;

int main()
{
    int ans = 0;
    scanf("%d",&t);
    while(t--)
    {
        int cnt1 = 0;
        int cnt2 = 0;
        int cnt3 = 0;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        int Max = 0;
        for(int i=0;i<n;i++)
        {
           if(a[i] == 0) continue;
           int cnt = 0;
           int flag = 0;
           for(int j=i;j<n;j++)
           {
               if(a[j] == 0) break;
                if(a[j] == 2) cnt++;
                if(a[j] == -2)
                {
                    flag = !flag;
                    cnt++;
                }
                if(!flag)
                Max = max(cnt,Max);
         }
        }
        printf("Case #%d: ",++ans);
        printf("%d\n",Max);
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值