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 <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main()
{
int n,t=,a[],i,j;
long long maxn,sum;
while(cin >> n)
{
memset(a,,sizeof(a));
for(i=;i<n;i++)
cin >> a[i];
for(i=,maxn=;i<n;i++)
{
for(j=i,sum=;j<n;j++)
{
sum *= a[j];//直接枚举起点到每个可能的终点的乘积
if(sum>maxn)
maxn = sum;
}
}
cout << "Case #" << t++ << ": The maximum product is " << maxn << "." << endl;
cout << endl;
}
return ;
}

Maximum Product UVA - 11059的更多相关文章

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

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

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

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

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

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK

  4. Uva 11059 Maximum Product

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

  5. UVa 11059 - Maximum Product 最大乘积【暴力】

    题目链接:https://vjudge.net/contest/210334#problem/B 题目大意:Given a sequence of integers S = {S1, S2, . . ...

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

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

  7. 【例题 7-2 UVA - 11059】Maximum Product

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] C语言for循环练习题 [代码] /* 1.Shoud it use long long ? 2.Have you ever tes ...

  8. UVA.10305 Maximum Product (暴力)

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

  9. UVa 11059 最大乘积

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

随机推荐

  1. 在Docker中部署Spring Boot项目

    想要获取更多文章可以访问我的博客 - 代码无止境. 微服务现在在互联网公司可谓非常流行了,之前找工作的的时候很多HR电话约面试的时候都会问对微服务是否有过接触.而微服务和Docker可以非常完美的结合 ...

  2. 使用verilog编写锁存器与触发器

    需要注意的地方有四点: 1.关于锁存器与触发器在原理上的不同点,以及代码的不同点 2.关于高电平有效与低电平有效之前的区别 3.理解实现复位与实现D触发器之间的区别 4.理解同步与异步之间的区别 锁存 ...

  3. 制造资源计划(Manufacturing Resource Planning,Mrp II)

        制造资源计划(Manufacturing Resource Planning,Mrp II)       概括: 以物料需求计划(MRP)为核心的企业生产管理计划系统,MRP II 是以工业工 ...

  4. .netcore持续集成测试篇之搭建内存服务器进行集成测试一

    系列目录 在web项目里,我们把每一层的代码的单元测试都通过并不代表程序能正常运行,因为这个过程缺失了http管道,很多时候我们还还需要把项目布在iis环境中或者在vs里启动iis express服务 ...

  5. echarts legend 限制规定显示个数,显示省略号,修改默认样式

    类似百度统计,有的时候legend的个数比较多,但是前端需要控制初始化显示的个数,以及最多显示的条数,先看效果图: 先给代码: <!DOCTYPE html> <html lang= ...

  6. 配置Windows Server 2008环境

    上一章已经把Windows Server2008操作系统安装完毕,接下来配置一下Windows Server环境.配置网络和共享中心.配置桌面环境.配置用户IE设置.安装Telnet远程工具.配置文件 ...

  7. Ubuntu下安装php7.1的gd,mysql,pdo_mysql扩展库

    执行以下命令 # apt-get install php7.1-gd # apt-get install php7.0-mysql 重新启动 php7.1-fpm(因为我是安装的 Nginx 和 ph ...

  8. 谨慎 mongodb 关于数字操作可能导致类型及精度变化

    1.问题描述 最近有一个需求,更新Mongo数据库中 原料 集合的某字段价格,更新后,程序报错了,说长度过长了,需要Truncation. 主要错误信息如下: FormatException: An ...

  9. LoRaWAN Server开源项目部署

    1,安装MQTT broker,Redis,PostgreSQL sudo apt install mosquitto mosquitto-clients redis-server redis-too ...

  10. rwcheck:为嵌入式设备设计的读写压测工具

    我设计的一款读写压测工具,开源在我的github仓库 rwcheck是一个对嵌入式设备进行读写压测的工具 什么是rwcheck 正如其名,rwcheck工具用于读写压测.它是什么工作原理呢?为什么要用 ...