UVa--11059 Maxumum Produce(枚举)
2016-02-06 14:39
267 查看
传送门
题意:
找出序列S的乘积最大的连续子序列,如果最大的乘积不是正数,输出0. 1 <= n <= 18, -10 <= Si <= 10.
题解:
数据规模小,直接枚举各个子序列,取其最大乘积。
注:UVa OJ的c++11编译器不支持%I64d输出,提交n多次才醒悟,泪。。
# include <iostream>
# include <cstdio>
# include <algorithm>
using namespace std;
const int maxn = 20;
int s[maxn];
int main()
{
int cases = 1, n;
while(cin >> n)
{
for(int i = 0; i < n; ++i)
cin >> s[i];
long long ans = 0;
long long tmp = 1;
for(int i = 0; i < n; ++i)
{
tmp = s[i];
ans = max(ans, tmp);
for(int j = i + 1; j < n; ++j){
tmp *= s[j];
ans = max(ans, tmp);
}
}
printf("Case #%d: The maximum product is %lld.\n\n", cases++, ans);
}
return 0;
}
题意:
找出序列S的乘积最大的连续子序列,如果最大的乘积不是正数,输出0. 1 <= n <= 18, -10 <= Si <= 10.
题解:
数据规模小,直接枚举各个子序列,取其最大乘积。
注:UVa OJ的c++11编译器不支持%I64d输出,提交n多次才醒悟,泪。。
# include <iostream>
# include <cstdio>
# include <algorithm>
using namespace std;
const int maxn = 20;
int s[maxn];
int main()
{
int cases = 1, n;
while(cin >> n)
{
for(int i = 0; i < n; ++i)
cin >> s[i];
long long ans = 0;
long long tmp = 1;
for(int i = 0; i < n; ++i)
{
tmp = s[i];
ans = max(ans, tmp);
for(int j = i + 1; j < n; ++j){
tmp *= s[j];
ans = max(ans, tmp);
}
}
printf("Case #%d: The maximum product is %lld.\n\n", cases++, ans);
}
return 0;
}
相关文章推荐
- RM格式压缩电影软件 Easy RealMedia Producer Full V1.94 下载
- C#编程中枚举类型的使用教程
- 枚举的用法详细总结
- PHP中Enum(枚举)用法实例详解
- c#入门之枚举和结构体使用详解(控制台接收字符串以相反的方向输出)
- 理解C#中的枚举(简明易懂)
- C#枚举中的位运算权限分配浅谈
- 在IE 浏览器中使用 jquery的fadeIn() 效果 英文字符字体加粗
- 比较简单的jquery教程 Easy Ajax with jQuery 中文版全集第1/3页
- Easy RM RMVB to DVD Burner v1.3.8 汉化版 下载 附注册码
- C++基础入门教程(四):枚举和指针
- FileShare枚举的使用小结(文件读写锁)
- Java枚举类用法实例
- 枚举窗口句柄后关闭所有窗口示例
- javascript模拟枚举的简单实例
- 深入剖析JavaScript中的枚举功能
- 枚举和宏的区别详细解析
- 深入理解C#中的枚举
- C#实现获取枚举中元素个数的方法
- 结合C++11的新特性来解析C++中的枚举与联合