UVa 11059 Maximum Product
生活随笔
收集整理的這篇文章主要介紹了
UVa 11059 Maximum Product
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題意:給出n個(gè)數(shù)組成的序列,求乘積最大的連續(xù)子序列
看的紫書,因?yàn)閚最大為18,每個(gè)數(shù)最大為10,所以10^18用long long 能夠存下, 直接枚舉起點(diǎn)和終點(diǎn)找最大值就可以了
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <cmath> 5 #include<stack> 6 #include<vector> 7 #include<map> 8 #include<queue> 9 #include<algorithm> 10 #define mod=1e9+7; 11 using namespace std; 12 13 typedef long long LL; 14 int a[105]; 15 16 int main(){ 17 LL ans,maxn; 18 int i,j,n,cas=1; 19 while(scanf("%d",&n)!=EOF){ 20 for(i=1;i<=n;i++) scanf("%d",&a[i]); 21 maxn=-1000; 22 23 for(i=1;i<=n;i++){ 24 ans=a[i]; 25 maxn=max(ans,maxn); 26 for(j=i+1;j<=n;j++){ 27 ans*=a[j]; 28 maxn=max(ans,maxn); 29 // printf("ans=%d\n",ans); 30 31 } 32 } 33 if(maxn<0) maxn=0; 34 printf("Case #%d: The maximum product is %lld.\n\n",cas++,maxn); 35 } 36 return 0; 37 } View Code?
轉(zhuǎn)載于:https://www.cnblogs.com/wuyuewoniu/p/4346025.html
總結(jié)
以上是生活随笔為你收集整理的UVa 11059 Maximum Product的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C#隐藏桌面图标和任务栏
- 下一篇: jquery动态改变图片