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 ...
随机推荐
- Python基础:lambda 匿名函数
格式 lambda argument1, argument2,... argumentN : expression square = lambda x: x**2 print(square(2)) 与 ...
- 学习环境搭建2——安装django
下载django https://www.djangoproject.com/download/ 选择最新的版本Latest release,下载后解压.在含有setup.py的文件夹中执行如下命令: ...
- AI:机器人与关键技术--总是被科普
AI:机器人与关键技术--总是被科普 原文链接:www.csdn.net/article/2014-04-22/2819430 机器人发展建议: 有需求才有生产,有更高的需求才有发展: 第一条:我们的 ...
- Here comes Treble: A modular base for Android
On the Android team, we view each dessert release as an opportunity to make Android better for our u ...
- BZOJ 1725: [Usaco2006 Nov]Corn Fields牧场的安排 状压动归
Description Farmer John新买了一块长方形的牧场,这块牧场被划分成M列N行(1<=M<=12; 1<=N<=12),每一格都是一块正方形的土地.FJ打算在牧 ...
- Xpath--使用Xpath爬取糗事百科成人版图片
#!usr/bin/env python#-*- coding:utf-8 _*-"""@author:Hurrican@file: 爬取糗事百科.py@time: 20 ...
- kali2018.2安装配置OpenVAS-9及错误处置
1 配置环境 1)虚拟机环境:VMware® Workstation 14 Pro(版本号:14.1.2 build-8497320),如图1. 图1 虚拟机版本信息 2)kali镜像 Kali201 ...
- 关于配置websocket,nginx转发https至wss问题
在本地测试通过的socket,再放到现在的有nginx代理之后发现会报:failed: Error in connection establishment: net::ERR_NAME_NOT_RES ...
- vue中使用base64进行加解密
vue进行Base64加解密 背景 项目中需要对特殊字符进行处理,避免json和数据库的特殊字符(""等)冲突,刚好学了信息安全,干脆整个加解密,wkk.. 使用步骤 打开dos, ...
- 运行级别(init)
一.运行级别(查看:cat /etc/inittab) 级别: 0:关机 1:服务器出问题(单用户状态) 2:无NFS的多用户模式 3:完整的多用户模式 4:无保留无使用 5:桌面模式 6:重新启动 ...