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. iptables基础及samba配置举例

    iptable基本概念 iptables防火墙包含两部分,即位于用户空间的iptables模块和位于内核空间netfilter模块.用户空间模块提供插入.修改和除去包过滤表中规则,内核模块进行实际的过 ...

  2. 一篇文章彻底弄清ARC始末

    本文转载至 http://blog.csdn.net/allison162004/article/details/38758265 自动引用计数(ARC)是编译器的一个特色,提供了Objective- ...

  3. Catalan数以及使用Raney引理证明

    一.Catalan数性质   1.1 令h(0)=1,h(1)=1,catalan数满足递推式:   h(n)= h(0)*h(n-1)+h(1)*h(n-2) + ... + h(n-1)h(0) ...

  4. EasyPlayer RTSP播放器OCX RegSvr32注册报错,DllRegisterServer调用失败,错误代码为0x80040200 解决方法

    问题描述 模块"EasyPlayer-RTSPWebActiveX.ocx" 已加载,但对DLLRegisterServer调用失败,错误代码为0x80040200. 解决方法 是 ...

  5. 17.Django表单验证

    Django提供了3中方式来验证表单 官网文档:https://docs.djangoproject.com/en/1.9/ref/validators 1.表单字段验证器 a.引入:from dja ...

  6. READ_TEXT

    [转自http://lz357502668.blog.163.com/blog/static/1649674320109119101907/]这里,定义ITAB内表来存储长文本,并放到内表ITAB_E ...

  7. ABAP下载xml文件

    [转http://www.cnblogs.com/byfhd/archive/2007/08/17/859829.html] ************************************* ...

  8. requests ip代理池单ip和多ip设置方式

    reqeusts库,在使用ip代理时,单ip代理和多ip代理的写法不同 (目前测试通过,如有错误,请评论指正) 单ip代理模式 省去headers等 import requests proxy = { ...

  9. MySQL常用代码

    create database 数据库名 create table CeShi1( Uid varchar(50) primary key, Pwd varchar(50), Name varchar ...

  10. Effective java -- 7 通用程序设计

    第四十五条:将局部变量的作用域最小化 第四十六条:加强版for循环优于传统for循环 第四十七条:了解和使用类库书中提到了一个生成随机数的例子.正好需要. public static void mai ...