UVA 11059
Given a sequence of integers S = {S1, S2, . . . , Sn}, you should determine what is the value of the
maximum positive product involving consecutive terms of S. If you cannot find a positive sequence,
you should consider 0 as the value of the maximum product.
Input
Each test case starts with 1 ≤ N ≤ 18, the number of elements in a sequence. Each element Si
is
an integer such that −10 ≤ Si ≤ 10. Next line will have N integers, representing the value of each
element in the sequence. There is a blank line after each test case. The input is terminated by end of
file (EOF).
Output
For each test case you must print the message: ‘Case #M: The maximum product is P.’, where
M is the number of the test case, starting from 1, and P is the value of the maximum product. After
each test case you must print a blank line.
Sample Input
3
2 4 -3
5
2 5 -1 2 -1
Sample Output
Case #1: The maximum product is 8.
Case #2: The maximum product is 20.
题意:输入n个元素组成的序列S,你需要找出一个乘积最大的连续子序列 。如果这个最大的乘积不是正数,就输出0(表示无解)。 1<=n<=18 -10<=S<=10
输出格式 每输出一组案例就空一行(注意)
题目分析:连续子序列有两个要素:起点和重点。所以只要枚举起点和终点就好。由于每个元素与的最大值不会超过10,且不超过18个元素,最大乘积不会超过10的18次方。所以可以用long long储存(试了一下,用int的话,输出18个10的结果不对,int存不下)
代码如下:(妈的,刚开始想到3重循环去了,还傻逼的循环了一个len表示子序列的长度,尽管试了很多案例都对了,就是不能过。重想了一下,抱着试一试的心态,写了,然后TM就过了,也是RLGL.....)
#include <stdio.h>
int a[];
int main()
{
int n,N=,c2=;
while(scanf("%d",&n)==)
{
long long c,c2=;
++N;
for(int i=; i<n; i++)
scanf("%d",&a[i]);
for(int q=;q<n;q++)
{
c=;
for(int z=q;z<n;z++)
{
c*=a[z];
if(c>c2)
c2=c;
}
}
if(c2<=)
printf("Case #%d: The maximum product is 0.\n\n",N);
else
printf("Case #%d: The maximum product is %lld.\n\n",N,c2);
}
return ;
}
UVA 11059的更多相关文章
- UVa 11059 最大乘积
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVa 11059 最大乘积 java 暴力破解
题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...
- uva 11059 maximum product(水题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK
- Uva 11059 Maximum Product
注意long long long long longlong !!!!!! 还有 printf的时候 明明longlong型的答案 用了%d WA了也看不出,这个细节要注意!!! #incl ...
- 最大乘积(Maximum Product,UVA 11059)
Problem D - Maximum Product Time Limit: 1 second Given a sequence of integers S = {S1, S2, ..., Sn}, ...
- 暴力求解——最大乘积 Maximum Product,UVa 11059
最大乘积 Maximum Product 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84562#problem/B 解题思路 ...
- UVa 11059 - Maximum Product 最大乘积【暴力】
题目链接:https://vjudge.net/contest/210334#problem/B 题目大意:Given a sequence of integers S = {S1, S2, . . ...
- UVA 11059 Maximum Product【三层暴力枚举起终点】
[题意]:乘积最大的子序列.n∈[1,10],s∈[-10,10] [代码]: #include<bits/stdc++.h> using namespace std; int a[105 ...
- 【例题 7-2 UVA - 11059】Maximum Product
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] C语言for循环练习题 [代码] /* 1.Shoud it use long long ? 2.Have you ever tes ...
随机推荐
- Python 字典排序
思路是把字典转为列表后再排序 d={'z':1,'y':2,'x':3} # 字典 s=d.items() # [('y', 2), ('x', 3), ('z', 1)] 列表 s.sort() # ...
- 小团队开发管理工具:gitlab+redmine+testlink+jenkins
由于工作需要,需要为团队搭建一个高效可用的开发管理平台.现在可用的开发管理工具很多开源的.商业的,网上也有很多博客和文章.经过2周的学习比较,再结合自己的项目特点,最后选定工具集:gitlab+red ...
- linux-搜索
grep显示文件中的匹配行 grep 参数 字符串 文件名 -c 输出匹配的行数 -v输出不匹配行 不加参数 :输出匹配的行 经常和管道符一起使用 eg:ps -ef|grep tom ...
- nineOldAnimation 应用
Android动画学习笔记-Android Animation 3.0以前,android支持两种动画模式,tween animation,frame animation,在android3.0中 ...
- 关于System.Collections空间
System.Collections命名空间包含可使用的集合类和相关的接口,提供了集合的基本功能. 该命名空间下的.NET非泛型集合类如下所示: — System.Collections.ArrayL ...
- Networking - ICMP 协议
发送到远程计算机的数据通常发经过一个或多个路由器,这些路由器在把数据传输到最终目的地的过程中可能发生多种问题.路由器利用 ICMP 把问题通知给源 IP.ICMP 还有用于其他调试和排错的功能. IC ...
- Viewpager+Fragment出现空白页面的问题
写了三个Fragment,一次点击跳转显示正常,如果从第一个直接跳转到第三个,第三个页面会出现空白界面. 问题找到了:原来动态获取数据页面数据不显示,页面显示空白,就是onCreateView每次都调 ...
- iOS 字体滚动效果 ScrollLabel
写了一个简单的字体滚动效果. 用了一种取巧的方式,传入两个一摸一样的Label(当然也可以是别的视图), 话不多说,代码里面讲解. SEScrollLabel.h #import <UIKit/ ...
- [Bootstrap]全局样式(四)
按钮 1.基本类.btn {display/padding/margin-bottom/font-size/border-radius/border} 作用于< a:role:button &g ...
- 0<=i<iLen 在C++中
for( i=0;0<= i<2; i++)这样的话会出现什么错误呢? 一直循环下去, 因为i>=一直成立