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& ...
随机推荐
- .net core开发从未如此简单,比abp更接地气
在谈起java一家独大的时候,dotnet人员总是一边嘲笑大量滥竽充数的java从业者,一边羡慕人家的生态.以前是只能羡慕,现在dotnet core开源了,我们都可以为dotnet core的开原生 ...
- 非UI线程更新界面
package com.caterSys.Thread; import java.text.SimpleDateFormat; import java.util.Date; import org.ec ...
- EnjoyingSoft之Mule ESB开发教程第六篇:Data Transform - 数据转换
目录 1. 数据转换概念 2. 数据智能感知 - DataSense 3. 简单数据转换组件 3.1 Object to JSON 3.2 JSON to XML 3.3 JSON to Object ...
- mac安装ElasticSearch+head+node+一个例子~
1.下载ElasticSearch 官网下载链接:https://www.elastic.co/cn/downloads/past-releases(进去的可能会比较慢,网络好的情况下会好一些) 我下 ...
- python异常处理-异常捕获-抛出异常-断言-自定义异常-UDP通信-socketserver模块应用-3
异常捕获 异常:程序在运行过程中出现了不可预知的错误,并且该错误没有对应的处理机制,那么就会以异常的形式表现出来 影响:整个程序无法再正常运行 异常的结构 异常的类型 NameError 异常的信息 ...
- Mysql索引进阶入门
1. 索引操作 MySQL 索引 菜鸟 2. 索引类型 PRIMARY 唯一且不能为空:一张表只能有一个主键索引 INDEX 普通索引 UNIQUE 唯一性索引 FULLTEXT 全文索引:用于搜索很 ...
- jvisualvm/Jconsole监控WAS中间件
1.登录was控制台https://196.168.119.18:9043/ibm/console/,找到自己的应用程序服务器---java和进程管理---进程定义--JAVA虚拟机,然后配置 通用J ...
- Notepad++编辑器——Verilog、代码片段、F6编译
Notepad++是一款精致小巧的编辑器,自带Verilog语法识别功能,插件也挺好用的.这里陈列一下我的设置. 版本:Notepad++ 7.6.6 ,32位 //================= ...
- vscode 配置 nodejs 开发环境
1.配置 cnpm 镜像 (国内淘宝镜像网速更快) npm install -g cnpm --registry=https://registry.npm.taobao.org 2.配置智能提示 安装 ...
- pip安装时使用国内源,加快下载速度
国内源: 新版ubuntu要求使用https源,要注意. 清华:https://pypi.tuna.tsinghua.edu.cn/simple 阿里云:http://mirrors.aliyun.c ...