首页 > 代码库 > UVa11059 Maximum Product (Two Pointers)

UVa11059 Maximum Product (Two Pointers)

链接: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)