您的位置:首页 > 其它

紫书章七 例题2 UVA 11059 Maximum Product

2017-03-09 18:01 281 查看
题意: 找最大乘积序列。

因为里面有负数嘛,我就想可不可以根据负数的个数来做文章。。后来总是WA。。因为还和负数的值有关。。还是老老实实暴力吧

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;
int p[30];
int main()
{
int n,temp=1;
while(scanf("%d",&n)!=EOF){
memset(p,0,sizeof(p));
long long ans=0;//这个是0.。。
for(int i=0;i<n;i++){scanf("%d",&p[i]);}
for(int i=0;i<n;i++){
long long ans1=1;
for(int j=i;j<n;j++){
ans1*=p[j];
if(ans1>ans) ans=ans1;
}
}
printf("Case #%d: The maximum product is ",temp++);cout<<ans;printf(".\n\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: