最大乘积(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 ...
随机推荐
- 编译android的linux kernel goldfish
https://source.android.com/source/building-kernels.html $ export PATH=/home/hzh/oldhome/learn/androi ...
- CentOS相关引导文件杂摘
1,EFI文件
- 用js判断一个复选框是否被选中
<html> <head> <title> 复选框全选.全不选.反选.必选一个 </title> ...
- PopupWindow源码分析
PopupWindow是我们经常使用的一个控件,严格来说这个PopuWindow就用来在指定位置显示一个View. 经过分析源码,PopupWindow里面没有Window对象,只是把View设置到屏 ...
- DataFromFile
#region Copyright 2013, Andreas Hoffmann // project location ==> http://datafromfile.codeplex.com ...
- lua字符匹配
匹配下列格式的数据中的 source和MAC地址: Chain WiFiDog_br-lan_Outgoing (1 references) pkts bytes target prot opt in ...
- 在LINUX中跟踪函数调用----http://stackoverflow.com/
http://stackoverflow.com/questions/311840/tool-to-trace-local-function-calls-in-linux I am looking f ...
- Cocos2d各版本搭建环境中的奇葩操作
#Version: Cocos2d-x 3.4 Android 将[Cocos2d-x解压目录]\cocos\platform\android\java\src中的com,org目录拷贝覆盖到[项目根 ...
- iOS UIKit:viewController之Segues (4)
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
- Android 开发实践 ViewGroup 实现左右滑出窗口(一)
利用假期把以前做的东西总结整理一下,先从简单的开始吧.实现的效果是这样的: 做了个截屏动画,比例有点不对了,凑合着看吧. 整个窗口有3部分组成,中间的主界面是个列表,左边的滑出界面是个菜单,右边的 ...