就是最大子段和的变体。最大子段和只要一个数组,记录前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 最大子段积的更多相关文章

  1. leecode 每日解题思路 152 Maximun Product Subarray

    问题描述: 问题链接:152 Maximum Product Subarray 在经典的算法解析中, 有关的分治和动态规划的,经典题型之一就是求最大子段和, 这道题就是他的变形:求最大子段积; 这个问 ...

  2. 152. Maximum Product Subarray 以及 讨论【最大连续子序列】

    题目大意: 连续最大子段积 题目思路: 最大值只能产生在一个正数x一个正数,一个负数乘一个负数,所以维护两个值,一个区间最大值,一个最小值 其他的话: 在讨论这个问题之前,我先来说一说大一刚开学就学了 ...

  3. LeetCode practice

    子集和问题:给定一组数和一个值,从这组数中选出若干个数使其和为给定的值.这是个NPC问题. 1.https://leetcode.com/problems/counting-bits/#/soluti ...

  4. AI面试刷题版

    (1)代码题(leetcode类型),主要考察数据结构和基础算法,以及代码基本功 虽然这部分跟机器学习,深度学习关系不大,但也是面试的重中之重.基本每家公司的面试都问了大量的算法题和代码题,即使是商汤 ...

  5. hdu4561 连续最大积

    题意: 连续最大积 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total ...

  6. hdu-4561 连续最大积( 水题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4561 求连续最大积. 他妈的狗逼思路到底咋说..... 思路是 %&*()*(&--))*)*& ...

  7. 最大子段和(c++)

    // 最大子段和.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> using namesp ...

  8. bzoj2693--莫比乌斯反演+积性函数线性筛

    推导: 设d=gcd(i,j) 利用莫比乌斯函数的性质 令sum(x,y)=(x*(x+1)/2)*(y*(y+1)/2) 令T=d*t 设f(T)= T可以分块.又由于μ是积性函数,积性函数的约束和 ...

  9. hdu1452 Happy 2004(规律+因子和+积性函数)

    Happy 2004 题意:s为2004^x的因子和,求s%29.     (题于文末) 知识点: 素因子分解:n = p1 ^ e1 * p2 ^ e2 *..........*pn ^ en 因子 ...

随机推荐

  1. Oracle 学习笔记(三)

    1.插入有日期的表,使用 to_date 函数 to_date('1992-12-07', 'yyyy-mm-dd'); 2.使用update更新语句的时候,既可以使用表达式或者数值直接修改数据,也可 ...

  2. 淘宝(taobao)HSF框架

    一.背景 随着网站访问量增加,仅仅靠增加机器已不能满足系统的要求,于是需要对应用系统进行垂直拆分和水平拆分.在拆分之后,各个被拆分的模块如何通信?如何保证 性能?如何保证各个应用都以同样的方式交互?这 ...

  3. Libsvm学习

        本篇博客转自 http://www.cppblog.com/guijie/archive/2013/09/05/169034.html     在电脑文件夹E:\other\matlab 20 ...

  4. SpringMVC学习总结(二)——DispatcherServlet详解

    摘要: DispatcherServlet是前端控制器设计模式的实现,提供Spring Web MVC的集中访问点,而且负责职责的分派,而且与Spring IoC容器无缝集成,从而可以获得Spring ...

  5. Java学习笔记之:Java 接口

    一.引言 接口(英文:Interface),在JAVA编程语言中是一个抽象类型,是抽象方法的集合,接口通常以interface来声明.一个类通过继承接口的方式,从而来继承接口的抽象方法. 接口并不是类 ...

  6. C++:对象数组

    对象数组 对象数组:每一个数组元素都是对象的数组,也就是说,若一个类有若干个对象,我们把这 一系列的对象用一个数组来存放.对应数组元素是对象,不仅具有的数据成员,而且还有函数 成员. @定义一个一维数 ...

  7. 修改linux命令行提示符路径显示

    命令显示行太长,影响观感,这样需要修改,具体方法: 1. 修改 ~/.bashrc,在最后一行添加: export PS1='[\u@\h\W]$' 其中\u是当前用户名,\h是当前主机名,\w显示当 ...

  8. C#Winfrom中,窗体加载时会自动执行一次控件的textchange事件,怎么让它不执行?

    http://zhidao.baidu.com/link?url=iTSyfa5_RJBSb37S8efdWoL5eDMrnxeAm-prhGSNBXqdP9r7PzNDQTc7gVzJgCNdzli ...

  9. 【HDOJ】4080 Stammering Aliens

    1. 题目描述给定一个长为$n \in [1, 4000]$的字符串,求其中长度最长的子串,并且该子串在原串中出现至少$m$次,并求最右起始位置. 2. 基本思路两种方法:二分+后缀数组,或者二分+哈 ...

  10. Android中LayoutInflater的使用

    Inflater英文意思是膨胀,在Android中应该是扩展的意思吧. LayoutInflater 的作用类似于 findViewById(),不同点是LayoutInflater是用来找layou ...