poj2018 Best Cow Fences
2012-09-29 23:39
399 查看
#include<iostream> #include<cstdio> #include<cstring> #define MAXSIZE 100500 #define sf scanf #define pf printf using namespace std; int N,F; int sum[MAXSIZE],t[MAXSIZE]; int stack[MAXSIZE],top,back; long long Xmult(int i,int j,int k) { return (long long )(i-j)*(sum[k]-sum[j])-(long long)(k-j)*(sum[i]-sum[j]); } void in_stack(int i) { while(top>=2&&Xmult(i,stack[top-1],stack[top-2])<=0) top--; stack[top++]=i; } int main() { while(~sf("%d%d",&N,&F)) { sum[0]=0; for(int i=1; i<=N; i++) { sf("%d",&t[i]); sum[i]=sum[i-1]+t[i]; } int i,j; top=back=0; long long ant=-1; for(i=F,j=0; i<=N; i++,j++) { in_stack(j); if(back>top-1) { long long temp; back=top-1; temp=(long long)(sum[i]-sum[stack[top-1]])*1000/(i-stack[top-1]); if(temp>ant) ant=temp; continue ; } while(back<top-1) { int x=stack[back]; int y=stack[back+1]; if((long long)(sum[i]-sum[y])*1000/(i-y)>=(long long)(sum[i]-sum[x])*1000/(i-x)) back++; else break; } long long temp; temp=(long long)(sum[i]-sum[stack[back]])*1000/(i-stack[back]); if(temp>ant) ant=temp; } pf("%lld\n",ant); } }
相关文章推荐
- poj 动态规划DP - 2018 Best Cow Fences
- poj 2018 Best Cow Fences USACO历年月赛 (分数规划+DP)
- poj 2018 Best Cow Fences
- POJ 2018 Best Cow Fences 笔记
- POJ - 2018 Best Cow Fences(DP)
- POJ 2018 Best Cow Fences
- [USACO2003][poj2018]Best Cow Fences(数形结合+单调队列维护)
- POJ 2018 Best Cow Fences
- POJ 2018 Best Cow Fences
- POJ2018 Best Cow Fences
- POJ 2018 Best Cow Fences
- 【斜率】【poj 2018】Best Cow Fences
- poj 2018 Best Cow Fences
- POJ 2018 Best Cow Fences
- POJ-2018 Best Cow Fences(二分加DP)
- POJ-2018 Best Cow Fences(二分加DP)
- poj 2018 Best Cow Fences dp+单调队列优化
- POJ 2018 Best Cow Fences(斜率优化+DP)
- POJ 2018 Best Cow Fences + UVA Live 4726 Average 斜率优化DP
- poj2018——Best Cow Fences