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 ...
随机推荐
- 第三方框架FMDB
摘要:关键点:创建.插入.查询.数据格式化 第三方框架FMDB -------------------------------------------------------------------- ...
- 从医生看病和快餐店点餐理解Node.js的事件驱动
第一个例子是关于医生看病. 在美国去看医生,需要填写大量表格,比如保险.个人信息之类,传统的基于线程的系统(thread-based system),接待员叫到你,你需要在前台填写完成这些表格,你站着 ...
- Mina的线程模型
在Mina的NIO模式中有三种I/O工作线程(这三种线程模型只在NIOSocket中有效,在NIO数据包和虚拟管道中没有,也不需要配置): IoAcceptor/IoConnector线程 IoPro ...
- fresco的源码学习自我总结
前言 对fresco框架源码的阅读学习,学习优秀的编码方式和较为实用常见设计模式,该篇讲得比较浅,主要是理清三个主要类的之间的关系. 本篇目录 fresco框架的MVC模式 fresco的Drawee ...
- CSS之照片翻转
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="C ...
- mysql补集合计算
mysql补集计算方法: 两表是1对多关系,user_id是关联字段,两表的数据量都是千万级别的 子查询实现 select count(*),sum(total_money) from A ...
- [求助]谁能给我讲解一下,iOS编程要如何实时显示采集到的图像???
rt,最近搞一个高清图传,本着自(bu)主(mai)创(da)新(jiang)的原则,打算利用手中的iPad当作辅助飞行屏幕,USB传输数据.再说某疆图传7999(还只支持自家云台录像拍照),哪是我这 ...
- 给label text 上色 && 给textfiled placeholder 上色
1.给label text 上色: NSInteger stringLength = ; stringLength = model.ToUserNickName.length; NSMutableAt ...
- C# ASPX.NET 文件(图片)下载
最好使用aspx页面写: protected void Page_Load(object sender,EventArgs e) { if(!IsPostBack) { System.Io.FileS ...
- 简单快速的伪Fractional Cascading
Fractional Cascading算法是用于将零散的多个数组(亦可理解成比较高维的空间)中的数据的二分查找速度增加,用的是空间换时间的方法.然而这种方法并不是很好懂,而且中文文献很少.在这里介绍 ...