UVA.10305 Maximum Product (暴力)
UVA.10305 Maximum Product (暴力)
题意分析
直接枚举起点和重点,然后算出来存到数组里面,sort然后取最大值即可。
代码总览
#include <iostream>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#define nmax 10000
#define MEM(x) memset(x,0,sizeof(x))
int number[nmax];
long long a[nmax];
using namespace std;
bool cmp(long long x, long long y)
{
if(x>y) return true;
else return false;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n;int kase = 1;
while(scanf("%d",&n) != EOF){
MEM(a);MEM(number);
for(int i = 1; i<=n; ++i) scanf("%d",&number[i]);
int cnt = 0;
for(int i = 1;i<=n;++i){
for(int j = i; j<=n;++j){
if(j == i){
a[cnt++] = number[i];
}else{
a[cnt] = a[cnt-1] * number[j];
cnt++;
}
}
}
sort(a,a+cnt,cmp);
printf("Case #%d: The maximum product is %lld.\n\n",kase++,a[0]>0?a[0]:0);
}
return 0;
}