Maximum Product UVA - 11059
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的更多相关文章
- 最大乘积(Maximum Product,UVA 11059)
Problem D - Maximum Product Time Limit: 1 second Given a sequence of integers S = {S1, S2, ..., Sn}, ...
- 暴力求解——最大乘积 Maximum Product,UVa 11059
最大乘积 Maximum Product 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84562#problem/B 解题思路 ...
- uva 11059 maximum product(水题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK
- Uva 11059 Maximum Product
注意long long long long longlong !!!!!! 还有 printf的时候 明明longlong型的答案 用了%d WA了也看不出,这个细节要注意!!! #incl ...
- UVa 11059 - Maximum Product 最大乘积【暴力】
题目链接:https://vjudge.net/contest/210334#problem/B 题目大意:Given a sequence of integers S = {S1, S2, . . ...
- UVA 11059 Maximum Product【三层暴力枚举起终点】
[题意]:乘积最大的子序列.n∈[1,10],s∈[-10,10] [代码]: #include<bits/stdc++.h> using namespace std; int a[105 ...
- 【例题 7-2 UVA - 11059】Maximum Product
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] C语言for循环练习题 [代码] /* 1.Shoud it use long long ? 2.Have you ever tes ...
- UVA.10305 Maximum Product (暴力)
UVA.10305 Maximum Product (暴力) 题意分析 直接枚举起点和重点,然后算出来存到数组里面,sort然后取最大值即可. 代码总览 #include <iostream&g ...
- UVa 11059 最大乘积
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
随机推荐
- css3系列之transform 详解rotate
rotate rotateX rotateY rotateZ rotate3d rotate: 旋转该元素,配合着transform-origin属性,transform-origin 是设置旋转点的 ...
- 从动态代理到Spring AOP(中)
一.前言 上一章节主要介绍了JDK动态代理和CGLIB动态代理:https://www.cnblogs.com/GrimMjx/p/11194283.html 这一章主要结合我们之前学习的动态代理的基 ...
- Maven项目的打包发布到Nexus私服和服务器
1.编写pom文件如下: <build> <plugins> <plugin> <groupId>org.apache.maven.plugins< ...
- 两份简单的logstash配置
input{http{port=>7474}} filter{ grok{ match =>{ #"message" => "%{COMBINEDAPA ...
- java中对事务的理解
一.什么是事务 事务是访问数据库的一个操作序列,数据库应用系统通过事务集来完成对数据库的存取. 二.事务的原则(ACID) 原子性:事务要么全部都被执行,要么就全都不被执行,如果有子事务提交失败,那么 ...
- Jenkins 配置 SpringBoot 自动构建部署
服务器版本 Linux version 3.10.0-957.12.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8 ...
- Python学习系列(四)Python 入门语法规则2
Python学习系列(四)Python 入门语法规则2 2017-4-3 09:18:04 编码和解码 Unicode.gbk,utf8之间的关系 2.对于py2.7, 如果utf8>gbk, ...
- 0x03 前缀和与差分
前缀和 [例题]BZOJ1218 激光炸弹 计算二位前缀和,再利用容斥原理计算出答案即可. #include <iostream> #include <cstdio> #inc ...
- 机器学习中的误差 Where does error come from?
误差来自于偏差和方差(bias and variance) 对于随机变量 X,假设其期望和方差分别为 μ 和 σ2.随机采样 N 个随机变量构成样本,计算算术平均值 m,并不会直接得到 μ (除非 ...
- 以股票案例入门基于SVM的机器学习
SVM是Support Vector Machine的缩写,中文叫支持向量机,通过它可以对样本数据进行分类.以股票为例,SVM能根据若干特征样本数据,把待预测的目标结果划分成“涨”和”跌”两种,从而实 ...