紫书章七 例题2 UVA 11059 Maximum Product
2017-03-09 18:01
387 查看
题意: 找最大乘积序列。
因为里面有负数嘛,我就想可不可以根据负数的个数来做文章。。后来总是WA。。因为还和负数的值有关。。还是老老实实暴力吧
因为里面有负数嘛,我就想可不可以根据负数的个数来做文章。。后来总是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; }
相关文章推荐
- 紫书章七 例题2 UVA 11059 Maximum Product
- 紫书章七 例题2 UVA 11059 Maximum Product
- 紫书章七 例题2 UVA 11059 Maximum Product
- 紫书章七 例题2 UVA 11059 Maximum Product
- 紫书章七 例题2 UVA 11059 Maximum Product
- 紫书章七 例题2 UVA 11059 Maximum Product
- 紫书章七 例题2 UVA 11059 Maximum Product
- 紫书章七例题八 Fill uva 10603
- 紫书章七例题八 Fill uva 10603
- 紫书章七例题八 Fill uva 10603
- 紫书章七例题八 Fill uva 10603
- 紫书章七例题八 Fill uva 10603
- 紫书章七例题八 Fill uva 10603
- 紫书章七例题八 Fill uva 10603
- UVa 11059 Maximum Product 例题(7-2)
- 紫书章七例题八 Fill uva 10603
- 【例题 7-2 UVA - 11059】Maximum Product
- 紫书 例题7-2 UVA 11059 暴力枚举
- 紫书第六章-----数据结构基础(例题6-11 四分树Quadtrees UVA - 297)
- 紫书动规 例题9-7 UVA - 11584 Partitioning by Palindromes dp