POJ 2796[UVA 1619] Feel Good
| Time Limit: 3000MS | Memory Limit: 65536K | |
| Total Submissions: 16786 | Accepted: 4627 | |
| Case Time Limit: 1000MS | Special Judge |
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
Source
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include <queue>
#include <vector>
#include<bitset>
#include<map>
using namespace std;
typedef long long LL;
const int maxn = 1e5+;
const int mod = +;
typedef pair<int,int> pii;
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define ms(a,b) memset(a,b,sizeof(a))
const int inf = 0x3f3f3f3f;
#define lson l,m,2*rt
#define rson m+1,r,2*rt+1
int a[maxn],sta[maxn];
LL sum[maxn];
int lef[maxn];
int main(){
// freopen("in.txt","r",stdin);
int n;
while(~scanf("%d",&n)){
ms(sum,); int top=-;
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
sum[i]=sum[i-]+a[i];
}
a[n+]=-;
LL ans=-;
int L,R;
for(int i=;i<=n+;i++){
// cout<<a[i]<<endl;
if(a[i]>sta[top] || top==-){
sta[++top]=a[i];
lef[top]=i;
// printf("%d,(%d,%d)\n",a[i],i,i);
}else if(a[i]<sta[top]){
int ll;
while(a[i]<sta[top]&&top>=){
ll=lef[top];
LL res=(sum[i-]-sum[lef[top]-])*sta[top]*1LL;
if(res > ans){
ans=res;
L=lef[top],R=i-;
}
top--;
}
sta[++top]=a[i];
lef[top]=ll;
// printf("%d,(%d,%d)\n",a[i],ll,i);
}
}
cout<<ans<<endl;
cout<<L<<" "<<R<<endl;
}
return ;
}
uva上能通过的代码
#include<cstdio>
#include<cstring>
#define maxn 1000010
long long sum[maxn];
int num[maxn], l[maxn], r[maxn], n;
void init() {
sum[] = ;
memset(num,-,sizeof(num));
for(int i = ; i <= n; i++) {
scanf("%d", &num[i]);
sum[i] = sum[i-] + num[i];
l[i] = i;
r[i] = i;
} for(int i = ; i <= n; i++) {
while(num[l[i] - ] >= num[i])
l[i] = l[l[i] - ];
}
for(int i = n; i >= ; i--) {
while(num[r[i] + ] >= num[i])
r[i] = r[r[i] + ];
}
} void solve() {
long long Max = ;
int ll = , rr = ;
long long s;
for(int i = ; i <= n; i++) {
s = num[i] * (sum[r[i]] - sum[l[i] - ]);
if(s > Max || (s == Max && rr - ll > r[i] - l[i])) {
Max = s;
ll = l[i];
rr = r[i];
}
}
printf("%lld\n%d %d\n", Max, ll, rr);
} int main() {
int cas = ;
while(scanf("%d", &n) != EOF) {
if(cas)
printf("\n");
cas++;
init();
solve();
}
return ;
}
POJ 2796[UVA 1619] Feel Good的更多相关文章
- POJ 2796 / UVA 1619 Feel Good 扫描法
Feel Good Description Bill is developing a new mathematical theory for human emotions. His recent ...
- 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(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 ...
- ZOJ 1914 Arctic Network (POJ 2349 UVA 10369) MST
ZOJhttp://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1914 POJhttp://poj.org/problem?id=23 ...
- POJ 2796:Feel Good(单调栈)
http://poj.org/problem?id=2796 题意:给出n个数,问一个区间里面最小的元素*这个区间元素的和的最大值是多少. 思路:只想到了O(n^2)的做法. 参考了http://ww ...
随机推荐
- Exception while invoking TaskListener: Exception while invoking TaskListener: null
https://community.alfresco.com/thread/225041-exception-while-invoking-tasklistener-null Ok, so the p ...
- Oracle10.2.0.1以及其他版本升级Oracle10.2.0.5的简单步骤
Oracle没有发布 完整版的 Oracle 10.2.0.5 的安装包,只能是通过安装完10.2.0.4 之后再升级10.2.0.5 这一点挺坑的. 建安记录一下步骤. 1. 挂载Oracle10. ...
- python之Map函数
# map()函数使用举例 # 功能:map()接受一个函数f和一个或多个list,将f依次作用在list的每个元素,得到一个新的列表 # 语法:map(方法名,列表,[列表2]) # 注意:map( ...
- C#中查看当前Request是否使用代理的一种方法
在程序中设置了代理,但是不知道如何判断是否真的使用了该代理, 在Visual Studio中可以使用以下方式来查看: 设置了代理 -> 在代码中WebRequest的实例处设置断点 -> ...
- poj3320(尺取法)
题目大意:给你一串数字,找出最小的能够覆盖所有出现过的数字的区间长度: 解题思路:依旧是尺取法,但要用map标记下出现过的书: 代码:别用cin输入: #include<iostream> ...
- C# == 和 Equals
先看一下解释 msdn对于 == 的解释: 对于预定义的值类型,如果操作数的值相等,则相等运算符 (==) 返回 true,否则返回 false. 对于 string 以外的引用类型,如果两个操作数引 ...
- 架构师成长之路3.1-Cobber原理及部署
点击返回架构师成长之路 架构师成长之路3.1-Cobber原理及部署 Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装.重装物理服务器和虚拟机,同时还可以管理 ...
- 如何同时修改SharePoint帐号和AD帐号的密码 - 批量修改SharePoint Managed Account
cls if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq ...
- 洛谷P4240 毒瘤之神的考验 【莫比乌斯反演 + 分块打表】
题目链接 洛谷P4240 题解 式子不难推,分块打表真的没想到 首先考虑如何拆开\(\varphi(ij)\) 考虑公式 \[\varphi(ij) = ij\prod\limits_{p | ij} ...
- luogu3810 陌上花开 (cdq分治)
求三维偏序 设三维为a,b,c.先对a排序,这样i的偏序就只能<i. 然而排序的时候需要三个维度都判断一遍,最后还要去重,不然会出现实际应该记答案的数出现在它后面的情况. (排序用的函数里不要写 ...