题目链接:https://vjudge.net/contest/210334#problem/B

题目大意:
Given a sequence of integers S = {S1, S2, . . . , Sn}, you should determine what is the value of the maximum positive product involving consecutive terms of S. If you cannot find a positive sequence, you should consider 0 as the value of the maximum product.

Input

Each test case starts with 1 ≤ N ≤ 18, the number of elements in a sequence. Each element Si is an integer such that −10 ≤ Si ≤ 10. Next line will have N integers, representing the value of each element in the sequence. There is a blank line after each test case. The input is terminated by end of file (EOF).

Output

For each test case you must print the message: ‘Case #M: The maximum product is P.’, where M is the number of the test case, starting from 1, and P is the value of the maximum product. After each test case you must print a blank line.

Sample Input

3

2 4 -3

5

2 5 -1 2 -1

Sample Output

Case #1: The maximum product is 8.

Case #2: The maximum product is 20.

即求数字的连续乘积最大值。

#include <cstdio>
#include <iostream>
using namespace std;
#define ll long long
#define INF -0x3f3f3f3f
int n;
;
];

int main()
{
    while (cin >> n)
    {
        int i, j;
        ; i <= n; i++)cin >> arr[i];
        ll maxn = INF;
        ; i <= n; i++)      //以该坐标为起点,开始乘它后面的数
        {
            ll sum = ;
            ; i+j<=n; j++)  //表示i要向后乘几位
            {
                sum *= arr[i+j];      //注意这里是i+j,要仔细体会,刚开始就是wrong在这里了
                if (sum > maxn)maxn = sum;    //每向后多多乘一位,都要和最大值比较一下,看能不能更新最大值
            }
        }
        )
        {
            cout << "Case #" << ++cas << ": The maximum product is " << maxn <<'.'<< endl<<endl;
        }
        else
        {
            cout << "Case #" << ++cas << ": The maximum product is 0." << endl<<endl;
        }
    }
    ;
}

2018-04-10

UVa 11059 - Maximum Product 最大乘积【暴力】的更多相关文章

  1. UVA 11059 Maximum Product【三层暴力枚举起终点】

    [题意]:乘积最大的子序列.n∈[1,10],s∈[-10,10] [代码]: #include<bits/stdc++.h> using namespace std; int a[105 ...

  2. uva 11059 maximum product(水题)——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK

  3. Uva 11059 Maximum Product

    注意long long  long long  longlong !!!!!!   还有 printf的时候 明明longlong型的答案 用了%d  WA了也看不出,这个细节要注意!!! #incl ...

  4. UVA.10305 Maximum Product (暴力)

    UVA.10305 Maximum Product (暴力) 题意分析 直接枚举起点和重点,然后算出来存到数组里面,sort然后取最大值即可. 代码总览 #include <iostream&g ...

  5. 152 Maximum Product Subarray 乘积最大子序列

    找出一个序列中乘积最大的连续子序列(该序列至少包含一个数).例如, 给定序列 [2,3,-2,4],其中乘积最大的子序列为 [2,3] 其乘积为 6.详见:https://leetcode.com/p ...

  6. Leetcode152. Maximum Product Subarray乘积的最大子序列

    给定一个整数数组 nums ,找出一个序列中乘积最大的连续子序列(该序列至少包含一个数). 示例 1: 输入: [2,3,-2,4] 输出: 6 解释: 子数组 [2,3] 有最大乘积 6. 示例 2 ...

  7. 暴力求解——最大乘积 Maximum Product,UVa 11059

    最大乘积 Maximum Product 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84562#problem/B 解题思路 ...

  8. 最大乘积(Maximum Product,UVA 11059)

    Problem D - Maximum Product Time Limit: 1 second Given a sequence of integers S = {S1, S2, ..., Sn}, ...

  9. Maximum Product UVA - 11059

    Given a sequence of integers S = {S1, S2, . . . , Sn}, you should determine what is the value of the ...

随机推荐

  1. react框架实现点击事件计数小案例

    下面将以一个小案例来讲解react的框架的一般应用,重点内容在代码段都有详细的解释,希望对大家有帮助 代码块: 代码块: import React from 'react'; import React ...

  2. Linux下搭建gtk+2.0开发环境

    安装gtk2.0 sudo apt-get install libgtk2.0-dev 查看 2.x 版本 pkg-config --modversion gtk+-2.0 #有可能需要sudo ap ...

  3. linux下mysql 5.7.22 安装

    二进制安装 1.下载https://dev.mysql.com/downloads/mysql/5.6.html#downloads 2.官方文档https://dev.mysql.com/doc/r ...

  4. ubuntu + usb转RS232驱动

    1. 购买USB转串RS232/485/422 如果你的电脑有串口的话,就不用买啦,我的台式机有串口,把USB转串的线插上之后,unbuntu就不支持了.(自己有嘛) 就是输入  ls /dev/tt ...

  5. Mac下的开发工具

    1.webstrom 淘宝上2块钱就能买一个 WebStorm 是jetbrains公司旗下一款JavaScript 开发工具.被广大中国JS开发者誉为“Web前端开发神器”.“最强大的HTML5编辑 ...

  6. UML和模式应用5:细化阶段(5)---系统顺序图

    1.前言 系统顺序图(SSD)是为阐述系统相关的输入和输出事件而快速.简单的创建的制品,它们是操作契约和对象设计的输入. SSD展示了直接与系统交互的外部参与者.系统(作为黑盒)以及由参与者发起的系统 ...

  7. 解决报错error the @annotation pointcut expression is only supported at Java 5

    eclipse搭建环境后报错 error the @annotation pointcut expression is only supported at Java 5 错误意思大致是:注释切入点表达 ...

  8. My Sql控制台命令

    1.连接Mysql 格式: mysql -h主机地址 -u用户名 -p用户密码 1.连接到本机上的MYSQL.首先打开DOS窗口,然后进入目录mysql\bin,再键入命令mysql -u root ...

  9. CentOS7图形界面与命令行界面切换

    1.如果在命令行模式,按Ctrl+Alt+F1,可以进入图形界面: 2.如果在图形界面下,按:Ctrl+Alt+F2,可以进入命令行模式:

  10. 升级 php composer 版本

    在执行 composer update 时,报错 You made a reference to a non-existent script @php artisan package:discover ...