hdu4561 bjfu1270 最大子段积
就是最大子段和的变体。最大子段和只要一个数组,记录前i个里的最大子段和在f[i]里就行了,但是最大子段积因为有负乘负得正这一点,所以还需要把前i个里的最小子段积存起来。就可以了。直接上代码:
/*
* Author : ben
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <numeric>
#include <cctype>
using namespace std;
//输入非负整数,用法int a = get_int();
int get_int() {
int res = , ch;
while (!((ch = getchar()) >= '' && ch <= '')) {
if (ch == EOF)
return -;
}
res = ch - '';
while ((ch = getchar()) >= '' && ch <= '')
res = res * + (ch - '');
return res;
}
//输入整数(包括负整数,故不能通过返回值判断是否输入到EOF,本函数当输入到EOF时,返回-1),用法int a = get_int2();
int get_int2() {
int res = , ch, flag = ;
while (!((ch = getchar()) >= '' && ch <= '')) {
if (ch == '-')
flag = ;
if (ch == EOF)
return -;
}
res = ch - '';
while ((ch = getchar()) >= '' && ch <= '')
res = res * + (ch - '');
if (flag == )
res = -res;
return res;
} const int MAXN = ;
int maxr[MAXN], minr[MAXN]; inline int mymul(int a, int b) {
int sign = ;
if (a * b == ) {
return ;
}
if (a * b < ) {
sign = -;
}
return sign * (abs(a) + abs(b));
} int main() {
int T = get_int(), tmp, N;
int a[];
for (int t = ; t <= T; t++) {
N = get_int();
maxr[] = minr[] = ;
int ans = ;
for (int i = ; i <= N; i++) {
tmp = get_int2() / ;
a[] = mymul(maxr[i - ], tmp);
a[] = mymul(minr[i - ], tmp);
a[] = tmp;
sort(a, a + );
maxr[i] = a[];
ans = maxr[i] > ans ? maxr[i] : ans;
minr[i] = a[];
}
printf("Case #%d: %d\n", t, ans);
}
return ;
}
hdu4561 bjfu1270 最大子段积的更多相关文章
- leecode 每日解题思路 152 Maximun Product Subarray
问题描述: 问题链接:152 Maximum Product Subarray 在经典的算法解析中, 有关的分治和动态规划的,经典题型之一就是求最大子段和, 这道题就是他的变形:求最大子段积; 这个问 ...
- 152. Maximum Product Subarray 以及 讨论【最大连续子序列】
题目大意: 连续最大子段积 题目思路: 最大值只能产生在一个正数x一个正数,一个负数乘一个负数,所以维护两个值,一个区间最大值,一个最小值 其他的话: 在讨论这个问题之前,我先来说一说大一刚开学就学了 ...
- LeetCode practice
子集和问题:给定一组数和一个值,从这组数中选出若干个数使其和为给定的值.这是个NPC问题. 1.https://leetcode.com/problems/counting-bits/#/soluti ...
- AI面试刷题版
(1)代码题(leetcode类型),主要考察数据结构和基础算法,以及代码基本功 虽然这部分跟机器学习,深度学习关系不大,但也是面试的重中之重.基本每家公司的面试都问了大量的算法题和代码题,即使是商汤 ...
- hdu4561 连续最大积
题意: 连续最大积 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total ...
- hdu-4561 连续最大积( 水题)
http://acm.hdu.edu.cn/showproblem.php?pid=4561 求连续最大积. 他妈的狗逼思路到底咋说..... 思路是 %&*()*(&--))*)*& ...
- 最大子段和(c++)
// 最大子段和.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> using namesp ...
- bzoj2693--莫比乌斯反演+积性函数线性筛
推导: 设d=gcd(i,j) 利用莫比乌斯函数的性质 令sum(x,y)=(x*(x+1)/2)*(y*(y+1)/2) 令T=d*t 设f(T)= T可以分块.又由于μ是积性函数,积性函数的约束和 ...
- hdu1452 Happy 2004(规律+因子和+积性函数)
Happy 2004 题意:s为2004^x的因子和,求s%29. (题于文末) 知识点: 素因子分解:n = p1 ^ e1 * p2 ^ e2 *..........*pn ^ en 因子 ...
随机推荐
- QAQ高精度模板笔记√
#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #i ...
- RN学习1——前奏,app插件化和热更新的探索
react_native_banner-min.png React Native(以下简称RN)有大量前端开发者的追捧.前端开发是一个活跃的社区,一直尝试着一统前后端,做一个全栈开发,RN就是他们在客 ...
- 客户端一个http连接包含两个方向,一个是这个http连接的输入,另一个是这个http连接的输出。
1.客户端一个http连接包含两个方向,一个是这个http连接的输入,另一个是这个http连接的输出. 利用httpclient进行ip地址和端口号连接后,http的输出端作为http请求参数设置.h ...
- WCF入门(九)--WCF实例管理
这组由Windows通讯基础(WCF)结合一组消息(客户端请求)服务实例所采用的技术被称为实例管理.一个完全由三种类型实例激活支持WCF,它们如下所述. 1.每个调用服务 每次调用服务是Windows ...
- create user 'root'@'localhost' identified by 。。。
- struct hw_module_t HAL_MODULE_INFO_SYM
先开个头,准备这与一篇struct hw_module_t HAL_MODULE_INFO_SYM 相关的文章. Hal层的库文件是怎么被上层调用的?上层调用时的入口(相当于main)又是什么呢?它就 ...
- NDK(14)Native的char*和Java的String相互转换
转自: http://www.cnblogs.com/canphp/archive/2012/11/13/2768937.html 首先确保C/C++源文件的字符编码是UTF-8与JAVA的class ...
- TeeChart的X轴,使用伪装的时间
TeeChart曲线的X轴是时间,但是频率很高.没法完全显示. 例如,一秒钟有2000个点,那么点与点的间隔为0.5毫秒. 使用TChart类的GetAxisLabel事件, 函数手册上对此事件的解释 ...
- Android开发之Android Context,上下文(Activity Context, Application Context)
转载:http://blog.csdn.net/lmj623565791/article/details/40481055 1.Context概念Context,相信不管是第一天开发Android,还 ...
- TUXEDO错误解决方案
错误1: root@tfjus:/opt/tuxedo/simpapp# buildclient -f simpcl.c -o simpcl simpcl.c: In function 'main': ...