1、题目名称

Maximum Product

2、题目地址

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2000

3、题目内容

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.

大致意思就是,给出一个序列,问这个序列中最大连续累乘的子序列中,最大的值为多少,如果都为负数,则输出0.

感受:  一定要记得用long long , 还有格式问题,否则可能pe

 #include"iostream"
using namespace std;
int a[];
int main(){
int n,out;
out=;
while(cin>>n){
for(int i=;i<n;i++)
cin>>a[i];
long long max=;
for(int i=;i<n;i++)
for(int j=i;j<n;j++){
long long z=;
for(int q=i;q<=j;q++)
z=z*a[q];
if(max<z) max=z;
}
cout<<"Case #"<<++out<<": The maximum product is "<<max<<"."<<endl<<endl; }
}

UVA11059 - Maximum Product的更多相关文章

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

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK

  2. [LeetCode] Maximum Product Subarray 求最大子数组乘积

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  3. 求连续最大子序列积 - leetcode. 152 Maximum Product Subarray

    题目链接:Maximum Product Subarray solutions同步在github 题目很简单,给一个数组,求一个连续的子数组,使得数组元素之积最大.这是求连续最大子序列和的加强版,我们 ...

  4. Uva 11059 Maximum Product

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

  5. LeetCode: Maximum Product Subarray && Maximum Subarray &子序列相关

    Maximum Product Subarray Title: Find the contiguous subarray within an array (containing at least on ...

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

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

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

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

  8. LeetCode Maximum Product Subarray(枚举)

    LeetCode Maximum Product Subarray Description Given a sequence of integers S = {S1, S2, . . . , Sn}, ...

  9. LeetCode 628. Maximum Product of Three Numbers (最大三数乘积)

    Given an integer array, find three numbers whose product is maximum and output the maximum product. ...

随机推荐

  1. 安装Linux CentOS与用Xshell实现远程连接

    注意,进入后有一个选择skip和OK的,选择skip 网络问题 vi /etc/sysconfig/network-scripts/ifcfg-eth0  //打开网络配置文件 ONBOOT=no  ...

  2. 什么是bin文件?

            知道多问bin文件几个为什么.是在出现下面这个问题时引发的.         出现这种问题:未能载入文件或程序集"DAL"或它的某一个依赖项. 系统找不到指定的文件 ...

  3. 数字证书转换cer---pem

    下载openssl-1.0.1s 安装好openssl之后,进入openssl目录:   输入openssl命令,即进入命令模式:   先将要转换的cer证书也放到openssl目录下面,然后执行以下 ...

  4. Python 集合、字典、运算符

    先区分一下序列类型和散列类型: 序列类型:list.string.tuple,他们中的元素是有序的. 散列类型:set.dict,他们中的元素无序的. 序列类型有序,可以用索引.而散列类型中的元素是无 ...

  5. Myeclipse 文件注释和解注释

    我用的是myeclipse10.6, 在xml中 注释可以用: ctrl+shift+/ (段落注释) ctrl+shift+c (行注释) 解除注释可以用: ctrl+shift+\ 在proper ...

  6. python 写一个类似于top的监控脚本

    最近老板给提出一个需要,项目需求大致如下:      1.用树莓派作为网关,底层接多个ZigBee传感节点,网关把ZigBee传感节点采集到的信息通过串口接收汇总,并且发送给上层的HTTP Serve ...

  7. 【BZOJ4928】第二题 树hash+倍增

    [BZOJ4928]第二题 Description 对于一棵有根树,定义一个点u的k-子树为u的子树中距离u不超过k的部分. 注意,假如u的子树中不存在距离u为k的点,则u的k-子树是不存在的. 定义 ...

  8. jqweui tabbar使用示例

    <!DOCTYPE html> <html class="pixel-ratio-1"> <head> <meta http-equiv= ...

  9. centos 安装composer PHP项目部署,Composer install Do not run Composer as root/super user!

    使用composer 安装项目的时候遇到了 Composer install Do not run Composer as root/super user! 在博客https://segmentfau ...

  10. js hoisting

    1.变量提升 var x = 2; function test(){ console.log(x) var x = 1; } ==>运行程序报错,在test()函数中,x被提升到了顶部声明,相当 ...