poj 2796 Feel Good
来源:互联网 发布:avision扫描仪软件 编辑:程序博客网 时间:2024/05/21 14:41
应该是用单调栈解决
用l[i] r[i] 存i点向左和向右比i点的值大的最多能到哪个位置
也就是 i 点所求的区间就是 l[i] 到 r[i]
再枚举每个点 求出符合题意的最优解
#include <iostream>#include <cstring>#include <string>#include <cstdio>#include <cmath>#include <algorithm>#include <vector>#include <queue>#include <map>#define inf 0x3f3f3f3fusing namespace std;int n,i,l[100010],r[100010],ansr,ansl;__int64 ans,tmp,ty[100010],sum[100010];int main(){ while(~scanf("%d",&n)) { sum[0]=0; for(i=1;i<=n;i++) { scanf("%I64d",&ty[i]); sum[i]=sum[i-1]+ty[i]; l[i]=i; r[i]=i; } for(i=2;i<=n;i++) { while(l[i]>1&&ty[l[i]-1]>=ty[i]) l[i]=l[l[i]-1]; } for(i=n-1;i>0;i--) { while(r[i]<n&&ty[r[i]+1]>=ty[i]) r[i]=r[r[i]+1]; } ans=-1; for(i=1;i<=n;i++) { tmp=ty[i]*(sum[r[i]]-sum[l[i]-1]); if(tmp>ans){ ansr=r[i]; ansl=l[i]; ans=tmp; } } printf("%I64d\n%d %d\n",ans,ansl,ansr); } 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
- ubuntu11.10 安装vmtools
- js继承有5种实现方式
- zoj 1088 System Overload
- Memcached 解析四
- 家用路由器会遭受攻击吗?
- poj 2796 Feel Good
- NYOJ770 仿射密码
- webkit在vs2008中编译
- Memcached 解析五
- ZOJ-2514
- CSS里面position:relative、absolute、static、relative总结
- Android Studio环境下关联Android源码
- 设计模式-行为型模式总结实例(二)
- union和distinct 的使用