[UVA11059]Maximum Product 暴力求解入门
2017-02-26 10:27
218 查看
[UVA11059]Maximum Product[暴力]
题意:给出一个序列,问这个序列中最大连续累乘的子序列中,最大的值为多少,如果都为负数,则输出0.
代码:#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn = 100;
long long num[maxn];
vector<int>v;
bool cmp(long long a,long long b)
{
return a>b;
}
int main()
{
int n;
int cnt = 0;
while(cin>>n)
{
memset(num,0,sizeof(num));
for(int i=0;i<n;i++)
{
cin>>num[i];
}
long long vis[maxn];
long long t = 1;
for(int i=0;i<n;i++)
{
t *=num[i];
v.push_back(t);
}
sort(v.begin(),v.end(),cmp);
long long temp = v.front();
if(temp <=0)
{
cout<<'0'<<"\n";
}
else {
cout<<"Case #"<<++cnt<<": The maximum product is "<<temp<<".\n";
}
v.clear();
}
return 0;
}
题意:给出一个序列,问这个序列中最大连续累乘的子序列中,最大的值为多少,如果都为负数,则输出0.
代码:#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn = 100;
long long num[maxn];
vector<int>v;
bool cmp(long long a,long long b)
{
return a>b;
}
int main()
{
int n;
int cnt = 0;
while(cin>>n)
{
memset(num,0,sizeof(num));
for(int i=0;i<n;i++)
{
cin>>num[i];
}
long long vis[maxn];
long long t = 1;
for(int i=0;i<n;i++)
{
t *=num[i];
v.push_back(t);
}
sort(v.begin(),v.end(),cmp);
long long temp = v.front();
if(temp <=0)
{
cout<<'0'<<"\n";
}
else {
cout<<"Case #"<<++cnt<<": The maximum product is "<<temp<<".\n";
}
v.clear();
}
return 0;
}
相关文章推荐
- 暴力求解——最大乘积 Maximum Product,UVa 11059
- [UVA11059]Maximum Product[暴力]
- uva 725 Division 暴力求解入门
- 【索引】算法竞赛入门经典-第7章 暴力求解法
- 11059 - Maximum Product(暴力)
- 最大乘积(Maximum Product,UVa11059)
- Maximum Product(暴力)
- Uva 725 Division (暴力搜索求解,入门题)
- UVA 11059 Maximum Product最大乘积(暴力法)
- LEETCODE: Maximum Product Subarray
- [leetcode oj]Maximum Product Subarray
- Hdu 1394-Minimum Inversion Number【暴力求解Or线段树Or树状数组】
- The Shortest Path Gym - 101498L 暴力求解?
- leetcode Maximum Product Subarray
- SVM入门(六)线性分类器的求解——问题的转化,直观角度
- SVM入门(五)线性分类器的求解——问题的描述Part2
- LeetCode 628 Maximum Product of Three Numbers
- LeetCode 318 Maximum Product of Word Lengths
- [leetCode]Maximum Product of Three Numbers
- UVA - 10483 The Sum Equals the Product 暴力