UVA11059 - Maximum Product
1、题目名称
Maximum Product
2、题目地址
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2000
3、题目内容
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.
大致意思就是,给出一个序列,问这个序列中最大连续累乘的子序列中,最大的值为多少,如果都为负数,则输出0.
感受: 一定要记得用long long , 还有格式问题,否则可能pe
#include"iostream"
using namespace std;
int a[];
int main(){
int n,out;
out=;
while(cin>>n){
for(int i=;i<n;i++)
cin>>a[i];
long long max=;
for(int i=;i<n;i++)
for(int j=i;j<n;j++){
long long z=;
for(int q=i;q<=j;q++)
z=z*a[q];
if(max<z) max=z;
}
cout<<"Case #"<<++out<<": The maximum product is "<<max<<"."<<endl<<endl; }
}
最新文章
- writing
- svn忽略某个文件提交
- jquery动态改变div宽度和高度
- 【原创&#183;总结】影响sql查询性能的因素
- 用python简单处理图片(4):图像中的像素访问
- Docker-数据卷和数据容器卷
- ubuntu14.04建立交叉编译环境, 注意事项
- QT 多线程程序设计【转】
- How to detect and avoid memory and resources leaks in .NET applications
- [转] 详细整理:UITableView优化技巧
- Subarray Sum Closest
- mysql-5.7.10-winx64 MySQL服务无法启动,服务没有报告任何错误的解决办法
- EL表达式学习
- 201521123072《java程序设计》第五周学习总结
- Git随笔 -- 初始化远程仓库
- [LeetCode] Majority Element 求大多数
- JavaScript权威指南--脚本化文档
- tornado-模板继承extend,函数和类的导入
- Hbase Scan的重要参数
- PowerDesigner15.1使用技巧总结
热门文章
- C语言基础知识【作用域规则】
- sublime中如何安装vue.js插件,并使代码高亮显示
- Mysql的学习研究
- 解决ubuntu中文乱码问题
- Myeclipse 文件注释和解注释
- 【BZOJ3991】[SDOI2015]寻宝游戏 树链的并+set
- EasyPlayer RTSP播放器OCX RegSvr32注册报错,DllRegisterServer调用失败,错误代码为0x80040200 解决方法
- c# 怎么更改DataTable 中某列的值?
- OSI模型第三层网络层-初识路由协议
- [Delphi]解决Delphi Distiller运行报错";HKEY_CURRENT_USER\\"; is of wrong kind or size