码迷,mamicode.com
首页 > 其他好文 > 详细

UVa11059 Maximum Product (Two Pointers)

时间:2016-09-03 21:04:11      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

链接:http://acm.hust.edu.cn/vjudge/problem/27946
分析:Two Pointers搞搞。

 1 #include <iostream>
 2 #include <algorithm>
 3 using namespace std;
 4 
 5 typedef long long LL;
 6 
 7 int n, a[20];
 8 
 9 LL gao() {
10     LL ans = 0;
11     for (int L = 0; L < n; L++) {
12         LL res = 1;
13         for (int R = L; R < n; R++) {
14                 res *= a[R];
15                 ans = max(ans, res);
16         }
17     }
18     return ans;
19 }
20 
21 int main() {
22     int kase = 0;
23     while (cin >> n) {
24         for (int i = 0; i < n; i++) cin >> a[i];
25         printf("Case #%d: The maximum product is %lld.\n\n", ++kase, gao());
26     }
27     return 0;
28 }

 

UVa11059 Maximum Product (Two Pointers)

标签:

原文地址:http://www.cnblogs.com/XieWeida/p/5837895.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!