比赛 |
20191022轻松模拟测试 |
评测结果 |
AAAAAAAAAAA |
题目名称 |
(USACO Dec18)平衡木 |
最终得分 |
100 |
用户昵称 |
jekyll |
运行时间 |
0.276 s |
代码语言 |
C++ |
内存使用 |
15.95 MiB |
提交时间 |
2019-10-22 19:23:46 |
显示代码纯文本
- #include<bits/stdc++.h>
- using namespace std;
-
- const int maxn=200005;
-
- inline int read(){
- register int x=0,w=1,ch=getchar();
- for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')w=-1;
- for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-48;
- return w*x;
- }
-
- int n,q[maxn],top;
- long long f[maxn];
-
-
- int main(){
- freopen("balance_beam.in","r",stdin);
- freopen("balance_beam.out","w",stdout);
- n=read();q[top=1]=0;
- for(int i=1;i<=n;i++)f[i]=read();
- for(int i=1;i<=n+1;i++){
- while(top>=2){
- if((f[i]-f[q[top]])*(1ll*q[top]-q[top-1])>(f[q[top]]-f[q[top-1]])*(1ll*i-q[top]))
- --top;
- else break;
- }
- q[++top]=i;
- }
- for(int i=1,j=1;i<top;i++){
- int l=q[i],r=q[i+1];
- for(;j<r;j++){
- double ans=(100000ll*f[l]*(r-j)+100000ll*f[r]*(j-l))/(double)(r-l);
- cout<<(long long)(ans+0.5)<<'\n';
- }
- }
- }
- /*
- 5
- 100000000
- 200000000
- 500000000
- 200000000
- 100000000
- */