POJ 2796 / UVA 1619 Feel Good 扫描法
Description
A new idea Bill has recently developed assigns a non-negative integer value to each day of human life.
Bill calls this value the emotional value of the day. The greater the emotional value is, the better the daywas. Bill suggests that the value of some period of human life is proportional to the sum of the emotional values of the days in the given period, multiplied by the smallest emotional value of the day in it. This schema reflects that good on average period can be greatly spoiled by one very bad day.
Now Bill is planning to investigate his own life and find the period of his life that had the greatest value. Help him to do so.
Input
Output
Sample Input
6
3 1 6 4 5 2
Sample Output
60
3 5
题意:
给你n个数,让你找到一个区间l,r使得(a[l] + a[l+1] + ......... + a[r-1]+a[r]) *min{a[l].....a[r]} 的值最大
题解:
我们预处理出对于每个i位置,以他为最小值时 向左向右能延伸的最远位值
答案就是扫一遍了,看看以哪个位置为最小的答案最大
在POJ上交比较好
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include<vector>
#include<map>
#include<queue>
using namespace std;
const int N = 1e5+, M = , mod = , inf = 1e9+; typedef long long ll;
const ll mm = 1e14;
int n;
ll a[N],l[N],r[N];
ll sum[N];
int main() {
int T = ;
while(scanf("%d",&n)!=EOF) {
if(T) cout<<endl; T++;
sum[] = ;
ll mi = mm;
for(int i=;i<=n;i++) scanf("%lld",&a[i]) ,sum[i] = sum[i-] + a[i] ,mi = min(mi,a[i]);
l[] = ;a[] = -;a[n+] = -;
for(int i=;i<=n;i++) {
int tmp = i-;
while(a[i]<=a[tmp]) tmp = l[tmp]-;
l[i] = tmp+;
}
r[n] = n;
for(int i=n-;i>=;i--) {
int tmp = i+;
while(a[i]<=a[tmp]) tmp = r[tmp] + ;
r[i] = tmp - ;
}
ll L = ,R = n;
ll mx = sum[n]*mi;
for(int i=;i<=n;i++) {
ll now = (sum[r[i]] - sum[l[i]-])*1ll*a[i];
if(now>mx) {
L = l[i]; R = r[i];
mx = now;
}
}
printf("%lld\n",mx);
printf("%lld %lld\n",L,R);
} return ;
}
POJ 2796 / UVA 1619 Feel Good 扫描法的更多相关文章
- POJ 2796[UVA 1619] Feel Good
Feel Good Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 16786 Accepted: 4627 Case T ...
- POJ 3525/UVA 1396 Most Distant Point from the Sea(二分+半平面交)
Description The main land of Japan called Honshu is an island surrounded by the sea. In such an isla ...
- uva 1619 - Feel Good || poj 2796 单调栈
1619 - Feel Good Time limit: 3.000 seconds Bill is developing a new mathematical theory for human ...
- UVA 1619 Feel Good 感觉不错 (扫描法)
Feel Good Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Bill is deve ...
- UVA - 1619 Feel Good(扫描法)
题目: 思路: 预处理出a[i]在哪个范围区间内是最小的,然后直接遍历a数组求答案就可以了. 这个预处理的技巧巧妙的用了之前的处理结果.(大佬tql) 代码: #include <bits/st ...
- UVA 1619 Feel Good(DP)
Bill is developing a new mathematical theory for human emotions. His recent investigations are dedic ...
- POJ 1002 UVA 755 487--3279 电话排序 简单但不容易的水题
题意:给你许多串字符串,从中提取电话号码,输出出现复数次的电话号码及次数. 以下是我艰难的AC历程:(这题估计是我刷的题目题解次数排前的了...) 题目不是很难理解,刚开始想到用map,但stl的ma ...
- [poj 2796]单调栈
题目链接:http://poj.org/problem?id=2796 单调栈可以O(n)得到以每个位置为最小值,向左右最多扩展到哪里. #include<cstdio> #include ...
- POJ 1011 / UVA 307 Sticks
中文题 (一般都比较坑) 思路:DFS (感谢学长的幻灯片) 这破题把我折腾惨了!!!搞了n天 // by Sirius_Ren #include <cstdio> #include &l ...
随机推荐
- Wannafly挑战赛25 C 期望操作数 数学
题目 题意:给你你一个数x和一个数q,x<=q,每一次可以等概率把x变成[x,q]中任意一个数,问变成q的步数的期望,输出对998244353取模,多组询问 题解:首先肯定的是,可以预处理,因为 ...
- tp框架---表单验证
自动验证是ThinkPHP模型层提供的一种数据验证方法,可以在使用create创建数据对象的时候自动进行数据验证.分为静态验证和动态验证. 关于基础知识,请查看手册“自动验证”一章. 一.静态验证 ( ...
- poj1111 Image Perimeters 广搜
题目大意: 输入一个矩阵,再输入其中一个“X”的位置(从1开始).从该位置向八个方向扩展,如果是“X”就可以并在一起.问最后得到的模块的周长是多少. 解题思路: 按照广搜的思路来做.用一个二维的数组标 ...
- Kafka 分布式消息系统详解
实际上kafka对机器的需求与Hadoop的类似. 原来,对于Linkin这样的互联网企业来说,用户和网站上产生的数据有三种: 需要实时响应的交易数据,用户提交一个表单,输入一段内容,这种数据最后是存 ...
- PostgreSQL的HA解决方案-2负载均衡(load balance)
一.部署说明 1.1 实施环境 本文档实验环境如下: PGSQL主机: 192.168.1.45 PGSQL备机: 192.168.1.50 软件和系统版本 Pgsql 版本: pgsql 9.2.4 ...
- 知识工程.Vs.软件构架,框架,设计模式.
软件工程-原文链接:http://tech.it168.com/a2009/0902/672/000000672853.shtml 此文章详细给出了软件设计的基本概念和用途,文章链接:http://w ...
- UVa 1585 待解决
是在遇到第一个ooxx的时候会出错,会少算一个1 #include<stdio.h> int main() { int i,k=0,sum=0; char a[100]={"oo ...
- vc++如何创建程序-设置断点-函数的覆盖,c++的多态性
---恢复内容开始--- 如何设置断点小笔记 将光标移动到你想设置断点的地方,按一下F9键即可,或者你可以用鼠标左键点击小手图标. CommentOut多行注释 函数的覆盖是在父类与子类之间的,函数的 ...
- centos7 rpm 安装 rabbitMQ 最新版
首先打开官网: http://www.rabbitmq.com/install-rpm.html 先到右侧导航栏来看一下 : 第一个红框是指的在linux中安装,全英文的,乱的一笔,但是静下心来就可以 ...
- 洛谷 P1328 生活大爆炸版石头剪刀布 模拟
很简单 Code: #include<cstdio> #include<queue> using namespace std; queue<int>A; queue ...