最大乘积(Maximum Product,UVA 11059)
Problem D - Maximum Product
Time Limit: 1 second
Given a sequence of integers S = {S1, S2, ..., Sn}, you should determine what is the value of the maximum positive product involving consecutive terms ofS. 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 elementSi is an integer such that-10 ≤ Si ≤ 10. Next line will haveN 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., whereM is the number of the test case, starting from1, andP 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 <stdio.h>
#include <set> using namespace std; int main(){
int n;
int * val = NULL;
set<long long> s;
while((scanf("%d",&n) == 1) && n != 0){
val = new int[n];
int i = 0;
for (;i < n; i++) {
scanf("%d",&val[i]);
}
s.clear();
int j ;
for(i = 0;i < n -1;i++){ //枚举起点 for (j = i; j < n; ++j) {//枚举终点
int k;long long ji = 1;
for(k = i; k <= j;k++){
ji *= val[k];
}
s.insert(ji);
} } long long max = *(s.rbegin());
if(max > 0){
printf("%ld\n",max);
}
else{
printf("0\n");
}
delete val;
} return 0; }
最大乘积(Maximum Product,UVA 11059)的更多相关文章
- 暴力求解——最大乘积 Maximum Product,UVa 11059
最大乘积 Maximum Product 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84562#problem/B 解题思路 ...
- Maximum Product UVA - 11059
Given a sequence of integers S = {S1, S2, . . . , Sn}, you should determine what is the value of the ...
- [Swift]LeetCode628. 三个数的最大乘积 | Maximum Product of Three Numbers
Given an integer array, find three numbers whose product is maximum and output the maximum product. ...
- [Swift]LeetCode318. 最大单词长度乘积 | Maximum Product of Word Lengths
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the tw ...
- 【LeetCode】1464. 数组中两元素的最大乘积 Maximum Product of Two Elements in an Array (Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力 找最大次大 日期 题目地址:https://le ...
- 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 ...
- uva 11059 maximum product(水题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK
- Uva 11059 Maximum Product
注意long long long long longlong !!!!!! 还有 printf的时候 明明longlong型的答案 用了%d WA了也看不出,这个细节要注意!!! #incl ...
随机推荐
- JavaScript DOM-Ready 机制
IE9开始和其他现代浏览器可以通过绑定DOMContentLoaded事件:IE9之前的的浏览器需要绑定onreadystatechange事件并等待readyState为"complete ...
- php 文本框里面显示数据库调出来的资料
php 文本框里面显示数据库调出来的资料,,,在里面我标注了,,那个地方为什么是!=才能显示正确的数据库资料啊?我理解的是对比正确输出数据库内容的.大师貌似不知道为什么就写错了 <html> ...
- [Python]Pip的安装以及简单的使用
Pip的安装 安装python以后(我的python版本是32位,版本号2.7.10),如果需要安装一些其他的库,一般有两种办法,一种是自己手动去各个库的官网下载,自己安装:另一种方法是安装pip,使 ...
- java对Ldap操作4
applicationContext.xml <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE ...
- Snake - SGU 128(构造多边形)
题目大意:有N个点,如果可以使用这N个点连接,连接的时候任意两条边要成直角,任意边都要平行于x轴或者y轴,并且不能出现跨立相交,最终组成一个闭合的多边形,求出来这个多边形的最小长度. 分析:容易证明这 ...
- js事件的方法
事件的方法:onclick 鼠标单击ondblclick 鼠标双击onkeyup 按下并释放键盘上的一个键时触发 onchange 文本内容或 ...
- spark 启动job的流程分析
从WordCount開始分析 编写一个样例程序 编写一个从HDFS中读取并计算wordcount的样例程序: packageorg.apache.spark.examples importorg.ap ...
- C#和java和android中的NetWorkAdapter,httpRequest,WebView,json,xml
原文地址:http://blog.csdn.net/intbird C#NetWorkAdapter 20121011.======================================== ...
- MVC系列之开始
4月5号晚本来应该写出来的,这几天迷上了炉石传说,打得有点疯,明天又得上班了,收拾心情还是得写出来.上星期5晚上回家的时候,不得不吐槽一下的确有点背.6点下班冲去江夏地铁站,赶7点15分到江门的轻轨 ...
- tcp ip参数详解
http://www.cnblogs.com/digdeep/p/4869010.html 1. TCP/IP模型 我们一般知道OSI的网络参考模型是分为7层:“应表会传网数物”——应用层,表示层,会 ...