p5155 [USACO18DEC]Balance Beam
Posted yzxverygood
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了p5155 [USACO18DEC]Balance Beam相关的知识,希望对你有一定的参考价值。
分析
https://www.luogu.org/blog/22112/solution-p5155
代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node {
int x,y;
};
node d[100100],a;
inline node operator - (node x,node y){return (node){x.x-y.x,x.y-y.y};}
inline int operator * (node x,node y){return x.x*y.y-x.y*y.x;}
signed main(){
int n,m=0,i,j,k;
scanf("%lld",&n);
for(i=1;i<=n+1;i++){
a.x=i;
if(i<=n)scanf("%lld",&a.y);
else a.y=0;
a.y*=100000;
while(m&&(a-d[m])*(d[m]-d[m-1])<=0)m--;
d[++m]=a;
}
for(i=1,j=0;i<=n;i++){
while(j<m&&d[j].x<i)j++;
if(d[j].x==i)printf("%lld
",d[j].y);
else printf("%lld
",((d[j].x-i)*d[j-1].y+
(i-d[j-1].x)*d[j].y)/(d[j].x-d[j-1].x));
}
return 0;
}
以上是关于p5155 [USACO18DEC]Balance Beam的主要内容,如果未能解决你的问题,请参考以下文章
[bzoj5483][Usaco2018 Dec]Balance Beam_凸包_概率期望