题目链接: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. HTML —— 小记

    标签语义化 所谓标签语义化是要使HTML标签具备很好的可读性,可以清晰传达每个标签所要表达的意义,以方便其被友好的处理和解析(主要针对网络爬虫) 好处: 1.对搜索引擎友好,增加排名权重 2.对用户友 ...

  2. python技巧 一等函数

    函数在python中作为一等函数,具有以下特点: 1.可以作为参数传递给其他函数 2.作为其他函数的值返回 3.能赋值给变量或数据结构中的元素 4.在运行的时候创建 In [1]: def add(x ...

  3. greenplum不能下载问题解决方法(转)

    到官网下载greenplum安装包的时候,可能会发现不能下载,提示: 出现这个问题的原因有几个方面: 最常见的原因是注册账号是填写了虚假或者无意义的信息,譬如名字是 123,地址是 abc. Pivo ...

  4. Sqoop异常:Please set $ACCUMULO_HOME to the root of your Accumulo installation.

    shell-init: 获取当前目录时出错: getcwd: 无法访问父目录: 没有那个文件或目录chdir: 获取当前目录时出错: getcwd: 无法访问父目录: 没有那个文件或目录chdir: ...

  5. django(二)中间件与面向切面编程

    一.中间件概念 django 自带函数可以在几个环节调节收到请求.处理请求.处理异常.以及发送请求. 看这里给的链接好了,这是一个大佬的讲django中间件的博客,非常清楚:https://www.c ...

  6. 转:Delphi中使用比较少的一些语法

    http://www.cnblogs.com/Murphieston/p/5577836.html 本文是为了加强记忆而写,这里写的大多数内容都是在编程的日常工作中使用频率不高的东西,但是又十分重要. ...

  7. Bootstrap2.x与Bootstrap3.x的区别

    做项目时,有时也会参考别的案例的优秀之处.在用Bootstrap的时候,发现很多项目代码都有区别,在<div>布局class上,有用.span*,有用.col-md-*,实际上是Boots ...

  8. python与redis

    1.什么是redis Redis 是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset ...

  9. php三种常用的加密解密算法

    方法一: /** * @param $string 要加密/解密的字符串 * @param string $operation 类型,ENCODE 加密:DECODE 解密 * @param stri ...

  10. 用PNChart绘制饼状图简介

    写在前面 最近做的小Demo中有一个绘制饼状图的需求.在开始实现之前上网了解了一下现有的一些绘制图形的第三方库,相应的库还是有挺多的,PNChart便是其中一个.PNChart是一个90后的中国boy ...