首页 > 其他 > 详细

「Luogu P5602」小E与美食

时间:2019-10-28 09:28:08      阅读:92      评论:0      收藏:0      [点我收藏+]

题目链接

戳我

\(Solution\)

这道题只需要枚举吃\(k\)个美食,最后在取前\(k\)大的美味值。对于每个算出答案后取\(max\)

\(Code\)

#include<bits/stdc++.h>
#define int __int128
#define rg register
#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
    while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();
    return f*x;
}
int a[3000001];
int sum[3000001];
bool cmp(int a,int b){
    return a>b;
}
main(){
    int n=read();
    long double maxx=0;
    for(int i=1;i<=n;i++)
        a[i]=read();
    sort(a+1,a+1+n,cmp);
    for(int i=1;i<=n;i++)
        sum[i]=sum[i-1]+a[i];
    for(int i=1;i<=n;i++)
        maxx=max(maxx,(long double)sum[i]*1.0/i*sum[i]);
    printf("%0.8Lf",maxx);
}

「Luogu P5602」小E与美食

原文:https://www.cnblogs.com/hbxblog/p/11750248.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!