比赛 20191022轻松模拟测试 评测结果 AAAAAAAAAAA
题目名称 (USACO Dec18)平衡木 最终得分 100
用户昵称 jekyll 运行时间 0.276 s
代码语言 C++ 内存使用 15.95 MiB
提交时间 2019-10-22 19:23:46
显示代码纯文本
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int maxn=200005;
  5.  
  6. inline int read(){
  7. register int x=0,w=1,ch=getchar();
  8. for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')w=-1;
  9. for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-48;
  10. return w*x;
  11. }
  12.  
  13. int n,q[maxn],top;
  14. long long f[maxn];
  15.  
  16.  
  17. int main(){
  18. freopen("balance_beam.in","r",stdin);
  19. freopen("balance_beam.out","w",stdout);
  20. n=read();q[top=1]=0;
  21. for(int i=1;i<=n;i++)f[i]=read();
  22. for(int i=1;i<=n+1;i++){
  23. while(top>=2){
  24. if((f[i]-f[q[top]])*(1ll*q[top]-q[top-1])>(f[q[top]]-f[q[top-1]])*(1ll*i-q[top]))
  25. --top;
  26. else break;
  27. }
  28. q[++top]=i;
  29. }
  30. for(int i=1,j=1;i<top;i++){
  31. int l=q[i],r=q[i+1];
  32. for(;j<r;j++){
  33. double ans=(100000ll*f[l]*(r-j)+100000ll*f[r]*(j-l))/(double)(r-l);
  34. cout<<(long long)(ans+0.5)<<'\n';
  35. }
  36. }
  37. }
  38. /*
  39. 5
  40. 100000000
  41. 200000000
  42. 500000000
  43. 200000000
  44. 100000000
  45. */