UVA 1619Feel Good 感觉不错 迭代法 (2005 NE)
来源:互联网 发布:sql server数据类型 编辑:程序博客网 时间:2024/06/06 09:44
题不难,迭代法。
#include<bits/stdc++.h>using namespace std;#define all(x) (x).begin(), (x).end()#define for0(a, n) for (int (a) = 0; (a) < (n); (a)++)#define for1(a, n) for (int (a) = 1; (a) <= (n); (a)++)typedef long long ll;typedef pair<int, int> pii;const int INF =0x3f3f3f3f;const int maxn= 1000000 ;int a[maxn+10],n;ll ans,sum[maxn+10];int ale,ari;int L[maxn+10],R[maxn+10];void update(ll val,int le,int ri){ if(val>ans) { ans=val; ale=le; ari=ri; }}void pre(){ sum[0]=0; sum[1]=a[1]; L[1]=1; for(int i=2;i<=n;i++) { sum[i]=sum[i-1]+a[i]; int p=i; while(p-1>=1&&a[p-1]>=a[i] ) { p=L[p-1]; } L[i]=p; } R[n]=n; for(int i=n-1;i>=1;i--) { int p=i; while(p+1<=n&&a[p+1]>=a[i]) { p=R[p+1]; } R[i]=p; }}void work(){ for1(i,n) { int le=L[i],ri=R[i]; ll t=sum[ri]-sum[le-1]; t*=a[i]; update(t,le,ri); }}int main(){ int kase=0; while(~scanf("%d",&n)) { if(kase++) putchar('\n'); for1(i,n) { scanf("%d",&a[i]); } ans=(ll)a[1]*a[1];//当初三个值初始化为-1,-1,-1不知道为何wa ale=1,ari=1; pre(); work(); printf("%lld\n%d %d\n",ans,ale,ari); } return 0;}
0 0
- UVA 1619Feel Good 感觉不错 迭代法 (2005 NE)
- 习题 8-18 UVA - 1619 Feel Good 感觉不错 (容斥定理)
- UVa 1619 Feel Good
- UVa - 1619 - Feel Good
- uva 1619 - Feel Good
- UVA 1619 Feel Good
- Feel Good - UVa 1619 dp
- UVA 1619 Feel Good(DP)
- UVA 1619(p256)----Feel Good
- 【UVA】1619-Feel Good(数据结构-栈)
- UVA - 1619 Feel Good 标记+枚举
- UVa 1619:Feel Good(单调栈)
- Feel Good UVA
- UVA - 1619 Feel Good(高效算法:滑动窗口)
- [UVa 1619] Feel Good (单调栈+前缀和)
- NEERC 2005 Feel Good (Poj2976)
- 单调队列——Feel Good(良好的感觉)
- Feel Good
- rsync安全配置
- xcode6创建empty application
- 【matlab】:matlab做的图片关联性识别算法
- 自定义GridView在展示Item时发生错位!
- 王坚清华夜话:未来不是阿里和谷歌的竞争 而是清华和斯坦福的竞争
- UVA 1619Feel Good 感觉不错 迭代法 (2005 NE)
- ACM is my refuge
- J2EE
- 关于mysql的DCL操作
- 第四周项目四(3)-程序分析
- ADO 与ADO.NET两种数据访问方式区别
- 魏佐夫博弈HDU1527
- Swift: Tuple 元组
- 阿里云飞天技术总架构师唐洪:飞天技术与应用