UVA11059 - Maximum Product
2016-04-14 17:50
323 查看
1、题目名称
Maximum Product
[b]2、题目地址[/b]
[b]https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2000[/b]
[b][b]3、题目内容[/b][/b]
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
Maximum Product
[b]2、题目地址[/b]
[b]https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2000[/b]
[b][b]3、题目内容[/b][/b]
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[20]; int main(){ int n,out; out=0; while(cin>>n){ for(int i=0;i<n;i++) cin>>a[i]; long long max=0; for(int i=0;i<n;i++) for(int j=i;j<n;j++){ long long z=1; 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; } }
相关文章推荐
- 【原】浅谈KL散度(相对熵)在用户画像中的应用
- mysql5.6主主集群自动同步脚本
- python脚本技巧
- SoC嵌入式软件架构设计之七:嵌入式文件系统设计
- 导步/数据库/队列---来源www.cnblogs.com/alex3714 金角大王
- 几种图片格式初级理解对比
- arduino随笔(3)
- Linux中madplay 音乐播放器移植步骤(在ubuntu中编译)
- Tomcat性能优化及JVM内存工作原理
- keyup()函数bug
- JS · 六-对象
- 【Uiautomator】手机系统测试----图库
- iOS陆哥开发笔记(十三) (Xcode统计代码行数)
- MD5算法原理
- [Unit Testing] Angular Test component with required
- swift一些常用的第三方的库
- 安装MongoDB到CentOS 6
- 【python学习】windows下安装MySQLdb
- Android与SNMP协议
- ThinkPHP 3.1.2 视图-2