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 ...
随机推荐
- CASS转ARCGIS
本文转载千浪兄弟博客 1.先看看这张图:CASS的扩展属性 ("south" (1000 . "310000")) 对应图斑属性编码“310000”,(&quo ...
- SSIS 学习(9):包部署常见问题汇总【转】
Integration Services 包在部署过程中,经常会出现这样那样的问题,让人摸不着头脑,很是烦人.下面我就将我在部署过程中,遇到的一些问题整理出来,以供大家参考. (一)SSIS包在SQL ...
- mongodb windows下的安装
(1)上mongodb的官网下载windows版本的mongo的安装包,安装包是绿色版的解压出来就可以直接使用. (2)将解压出来的bin文件夹复制到c:\mongoDB下(c:\mongoDB这个文 ...
- jquery手写焦点轮播图-------解决最后一张无缝跳转第一张的问题
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- [转]在 Windows Server 2012 上安装 IIS 8
本文转自:http://www.starland.net.cn/blog/view/158/1.aspx 本文译自:http://learn.iis.net/page.aspx/1088/instal ...
- [改善Java代码]推荐覆写toString方法
建议49: 推荐覆写toString方法 为什么要覆写toString方法,这个问题很简单,因为Java提供的默认toString方法不友好,打印出来看不懂,不覆写不行,看这样一段代码: public ...
- Angular 全局页面切换动画 me-pageloading
最近看了Codrops的一篇文章, 里面讲到了一个页面切换的效果, 详情点击此处. 看了这个效果感觉很赞, 觉得这个效果可以用在angular的页面切换中, 所以将这个效果移植到angular中, 做 ...
- Git CMD - tag: Create, list, delete or verify a tag object signed with GPG
命令格式 git tag [-a | -s | -u <keyid>] [-f] [-m <msg> | -F <file>] <tagname> [& ...
- KSImageNamed-Xcode插件在xcode 6.4/6.3或其他版本中不能使用解决方案
大家都知道这个插件很强大,但是现在这个插件最新版貌似只支持xcode7 ,需要修改KSImageNamed-xcode中的一个配置文件,添加uuid才能使他支持xcode6.3或6.4 进入下载的插件 ...
- Objective-C 【单个对象内存管理(野指针&内存泄露)】
------------------------------------------- 单个对象内存管理 (1)野指针 ①定义了一个指针变量,但是并没有赋初值,它随机指向一个东西 ②某指针变量指向的内 ...