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.....)

  1. #include <stdio.h>
  2. int a[];
  3. int main()
  4. {
  5. int n,N=,c2=;
  6. while(scanf("%d",&n)==)
  7. {
  8. long long c,c2=;
  9. ++N;
  10. for(int i=; i<n; i++)
  11. scanf("%d",&a[i]);
  12. for(int q=;q<n;q++)
  13. {
  14. c=;
  15. for(int z=q;z<n;z++)
  16. {
  17. c*=a[z];
  18. if(c>c2)
  19. c2=c;
  20. }
  21. }
  22. if(c2<=)
  23. printf("Case #%d: The maximum product is 0.\n\n",N);
  24. else
  25. printf("Case #%d: The maximum product is %lld.\n\n",N,c2);
  26. }
  27. return ;
  28. }

UVA 11059的更多相关文章

  1. UVa 11059 最大乘积

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  2. UVa 11059 最大乘积 java 暴力破解

    题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...

  3. uva 11059 maximum product(水题)——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK

  4. Uva 11059 Maximum Product

    注意long long  long long  longlong !!!!!!   还有 printf的时候 明明longlong型的答案 用了%d  WA了也看不出,这个细节要注意!!! #incl ...

  5. 最大乘积(Maximum Product,UVA 11059)

    Problem D - Maximum Product Time Limit: 1 second Given a sequence of integers S = {S1, S2, ..., Sn}, ...

  6. 暴力求解——最大乘积 Maximum Product,UVa 11059

    最大乘积 Maximum Product 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84562#problem/B 解题思路 ...

  7. UVa 11059 - Maximum Product 最大乘积【暴力】

    题目链接:https://vjudge.net/contest/210334#problem/B 题目大意:Given a sequence of integers S = {S1, S2, . . ...

  8. UVA 11059 Maximum Product【三层暴力枚举起终点】

    [题意]:乘积最大的子序列.n∈[1,10],s∈[-10,10] [代码]: #include<bits/stdc++.h> using namespace std; int a[105 ...

  9. 【例题 7-2 UVA - 11059】Maximum Product

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] C语言for循环练习题 [代码] /* 1.Shoud it use long long ? 2.Have you ever tes ...

随机推荐

  1. CASS转ARCGIS

    本文转载千浪兄弟博客 1.先看看这张图:CASS的扩展属性 ("south" (1000 . "310000")) 对应图斑属性编码“310000”,(&quo ...

  2. SSIS 学习(9):包部署常见问题汇总【转】

    Integration Services 包在部署过程中,经常会出现这样那样的问题,让人摸不着头脑,很是烦人.下面我就将我在部署过程中,遇到的一些问题整理出来,以供大家参考. (一)SSIS包在SQL ...

  3. mongodb windows下的安装

    (1)上mongodb的官网下载windows版本的mongo的安装包,安装包是绿色版的解压出来就可以直接使用. (2)将解压出来的bin文件夹复制到c:\mongoDB下(c:\mongoDB这个文 ...

  4. jquery手写焦点轮播图-------解决最后一张无缝跳转第一张的问题

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. [转]在 Windows Server 2012 上安装 IIS 8

    本文转自:http://www.starland.net.cn/blog/view/158/1.aspx 本文译自:http://learn.iis.net/page.aspx/1088/instal ...

  6. [改善Java代码]推荐覆写toString方法

    建议49: 推荐覆写toString方法 为什么要覆写toString方法,这个问题很简单,因为Java提供的默认toString方法不友好,打印出来看不懂,不覆写不行,看这样一段代码: public ...

  7. Angular 全局页面切换动画 me-pageloading

    最近看了Codrops的一篇文章, 里面讲到了一个页面切换的效果, 详情点击此处. 看了这个效果感觉很赞, 觉得这个效果可以用在angular的页面切换中, 所以将这个效果移植到angular中, 做 ...

  8. 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> [& ...

  9. KSImageNamed-Xcode插件在xcode 6.4/6.3或其他版本中不能使用解决方案

    大家都知道这个插件很强大,但是现在这个插件最新版貌似只支持xcode7 ,需要修改KSImageNamed-xcode中的一个配置文件,添加uuid才能使他支持xcode6.3或6.4 进入下载的插件 ...

  10. Objective-C 【单个对象内存管理(野指针&内存泄露)】

    ------------------------------------------- 单个对象内存管理 (1)野指针 ①定义了一个指针变量,但是并没有赋初值,它随机指向一个东西 ②某指针变量指向的内 ...