博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVA11059 - Maximum Product
阅读量:5098 次
发布时间:2019-06-13

本文共 1434 字,大约阅读时间需要 4 分钟。

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

1 #include"iostream" 2 using namespace std; 3 int a[20]; 4 int main(){ 5     int n,out; 6     out=0; 7     while(cin>>n){ 8         for(int i=0;i
>a[i];10 long long max=0;11 for(int i=0;i

 

转载于:https://www.cnblogs.com/hutonm/p/5392053.html

你可能感兴趣的文章
我的博客开通啦~
查看>>
python 使用 Pyscript 调试 报错
查看>>
DTCMS插件的制作实例电子资源管理(四)URL重写
查看>>
南阳acm-97-兄弟郊游问题(水题)
查看>>
java文件cmd运行出现中文乱码
查看>>
算法图解(选择排序)
查看>>
Python全栈 MongoDB 数据库(Mongo、 正则基础、一篇通)
查看>>
依旧忙碌——4.9
查看>>
stop()在animate中的用法
查看>>
面向对象进阶
查看>>
Android studio gradle配置完整版(转)
查看>>
Pair Project 初体验(By Cuilin Lan & Xiao Fang)
查看>>
IOS使用mkdir创建目录
查看>>
冒泡排序实例
查看>>
my code review
查看>>
Linux下环境变量配置方法梳理(.bash_profile和.bashrc的区别)
查看>>
[Luogu1216][USACO1.5]数字三角形 Number Triangles
查看>>
张云飞 201771010143 《面对对象程序设计(java)》第十四周学习总结 第十三组
查看>>
2019 蓝桥杯省赛 A 组模拟赛(一)-忽明忽暗
查看>>
mysql数据库中导入txt文本数据的方法
查看>>