UVa 11059 - Maximum Product 最大乘积【暴力】
题目链接:https://vjudge.net/contest/210334#problem/B
题目大意:
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.
即求数字的连续乘积最大值。
#include <cstdio>
#include <iostream>
using namespace std;
#define ll long long
#define INF -0x3f3f3f3f
int n;
;
];
int main()
{
while (cin >> n)
{
int i, j;
; i <= n; i++)cin >> arr[i];
ll maxn = INF;
; i <= n; i++) //以该坐标为起点,开始乘它后面的数
{
ll sum = ;
; i+j<=n; j++) //表示i要向后乘几位
{
sum *= arr[i+j]; //注意这里是i+j,要仔细体会,刚开始就是wrong在这里了
if (sum > maxn)maxn = sum; //每向后多多乘一位,都要和最大值比较一下,看能不能更新最大值
}
}
)
{
cout << "Case #" << ++cas << ": The maximum product is " << maxn <<'.'<< endl<<endl;
}
else
{
cout << "Case #" << ++cas << ": The maximum product is 0." << endl<<endl;
}
}
;
}
2018-04-10
UVa 11059 - Maximum Product 最大乘积【暴力】的更多相关文章
- UVA 11059 Maximum Product【三层暴力枚举起终点】
[题意]:乘积最大的子序列.n∈[1,10],s∈[-10,10] [代码]: #include<bits/stdc++.h> using namespace std; int a[105 ...
- uva 11059 maximum product(水题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK
- Uva 11059 Maximum Product
注意long long long long longlong !!!!!! 还有 printf的时候 明明longlong型的答案 用了%d WA了也看不出,这个细节要注意!!! #incl ...
- UVA.10305 Maximum Product (暴力)
UVA.10305 Maximum Product (暴力) 题意分析 直接枚举起点和重点,然后算出来存到数组里面,sort然后取最大值即可. 代码总览 #include <iostream&g ...
- 152 Maximum Product Subarray 乘积最大子序列
找出一个序列中乘积最大的连续子序列(该序列至少包含一个数).例如, 给定序列 [2,3,-2,4],其中乘积最大的子序列为 [2,3] 其乘积为 6.详见:https://leetcode.com/p ...
- Leetcode152. Maximum Product Subarray乘积的最大子序列
给定一个整数数组 nums ,找出一个序列中乘积最大的连续子序列(该序列至少包含一个数). 示例 1: 输入: [2,3,-2,4] 输出: 6 解释: 子数组 [2,3] 有最大乘积 6. 示例 2 ...
- 暴力求解——最大乘积 Maximum Product,UVa 11059
最大乘积 Maximum Product 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84562#problem/B 解题思路 ...
- 最大乘积(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
Given a sequence of integers S = {S1, S2, . . . , Sn}, you should determine what is the value of the ...
随机推荐
- mysql数据库导出excel xml等格式文件
http://jingyan.baidu.com/article/ac6a9a5e43a62e2b653eac83.html
- ActiveMQ学习笔记1
1.接口 JMS 公共 点对点域 发布/订阅域 ConnectionFactory QueueConnectionFactory TopicConnectionFactory Connection Q ...
- Linux时间日期类指令
⒈date [Options] 显示/设置当前日期 基本语法: date 显示当前时间 date +"%Y" 显示当前年份 date +"%m" 显示当前月份 ...
- freeRTOS中文实用教程2--队列
1.前言 freeRTOS中所有任务的通信和同步机制都是基于队列来实现. 2.队列的特点 图 队列的读写操作 队列的数据存储 (1)队列可以保存有限个具有确定长度的数据单元,队列可以保存的最大单元数目 ...
- kali Linux下wifi密码安全测试(1)虚拟机下usb无线网卡的挂载 【转】
转自:http://blog.chinaunix.net/uid-26349264-id-4455634.html 目录 kali Linux下wifi密码安全测试(1)虚拟机下usb无线网卡的挂载 ...
- Javascript构造函数的继承
仅供学习参考,原文链接:http://www.ruanyifeng.com/blog/2010/05/object-oriented_javascript_inheritance.html 今天要介绍 ...
- cactiez v11添加对mysql数据库、apache系统进行监控
cactiez默认已经安装了mysql监控的模板,需要我们对服务器端和被监控的mysql客户端进行配置才能生效. 被监控的Mysql客户端: 如cactiez的IP为192.168.0.8 #添加一个 ...
- win7设置固定IP
正文: 你必须知道你的路由器网关,一般是192.168.1.1(或192.168.0.1) 按传统的来:开始——控制面板——网络和共享中心——更改适配器设置.一般来讲,这里应该有两个图标,一个是有线网 ...
- LINUX-CUDA版本所对应的NVIDIA驱动版本号,cuda版本报错的朋友参考一下
CUDA 10.0: 410.48 CUDA .xx CUDA .xx (update) CUDA .xx CUDA .xx (GA2) CUDA .4x CUDA .xx CUDA .xx CUDA ...
- android录音实现不再担心—一个案例帮你解决你的问题
最近有小伙伴经常android的录音怎么实现,有没有相关的案例.今天给大家推荐一个android中实现录音和播放的小案例. 效果图: 一.实现录音的 Service 关键代码: // 开始录音 pub ...