poj 2796 Feel Good
来源:互联网 发布:js 检测div大小变化 编辑:程序博客网 时间:2024/06/10 13:26
Description
Bill is developing a new mathematical theory for human emotions. His recent investigations are dedicated to studying how good or bad days influent people's memories about some period of life.
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.
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.
题意是给出一串数,求给定的范围内最小值乘该范围内所有值的和的最大值
方法和poj 2559相同,仍然是假设某一点的数值是最小的,求左右两端可到达的最远的位置
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#define MAX_N 100000using namespace std;int n,a[MAX_N+5],l[MAX_N+5],r[MAX_N+5];int main(){ while(~scanf("%d",&n)) { long long sum[MAX_N+5]; for(int i=1;i<=n;i++) scanf("%d",&a[i]); l[0]=0,r[n+1]=0; for(int i=1;i<=n;i++) { int k=i-1; while(k>0&&a[i]<=a[k]) k=l[k]-1; l[i]=++k; } for(int i=n;i>=1;i--) { int k=i+1; while(k<n+1&&a[i]<=a[k]) k=r[k]+1; r[i]=--k; } sum[0]=0,sum[1]=a[1]; for(int i=2;i<=n;i++) sum[i]=sum[i-1]+a[i]; long long maxn=-1; int maxi; for(int i=1;i<=n;i++) { long long q=sum[r[i]]-sum[l[i]-1]; q=a[i]*q; if(q>maxn) { maxn=q; maxi=i;} } printf("%lld\n",maxn); printf("%d %d\n",l[maxi],r[maxi]); } return 0;}
阅读全文
0 0
- poj 2796 Feel Good
- POJ 2796 Feel Good
- POJ 2796 Feel Good
- poj 2796 Feel Good
- poj 2796 feel good
- POJ-2796-Feel Good
- POJ 2796Feel Good
- poj 2796 Feel Good
- POJ 2796 Feel Good
- poj 2796 Feel Good
- Poj-2796 Feel Good
- POJ 2796 Feel Good
- poj 2796 Feel Good
- poj 2796Feel Good
- POJ 2796 Feel Good
- POJ 2796 Feel Good
- poj 2796 Feel Good
- POJ 2796 Feel Good
- ubuntu the system is running in low-graphics mode 解决办法
- BinarySearch-----50. Pow(x, n)
- 设计模式——装饰者模式
- 快速运动的物体穿过目标体的解决办法
- 第一篇博客
- poj 2796 Feel Good
- vscode 快捷键, 插件 资料指南 (持续更新)
- UVALive
- python_jieba分词的使用
- 二维数组
- HTML5 -video和audio的设置
- 存储过程 游标嵌套
- XZ_iOS之Runtime使用运行时获取类的属性列表
- 前段.微信小程序开发Ⅰ(结构、逻辑、工作流)