1 Star 0 Fork 0

util6/算法刷题c++

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Acwing1235PaymentProblem.cpp 759 Bytes
一键复制 编辑 原始数据 按行查看 历史
util6 提交于 2022-04-02 21:39 +08:00 . 默认的
//
// Created by 刘宇韬 on 2022/3/30.
//
/**
* @author 大菜狗
*/
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define pb push_back
#define fi first
#define se second
const int N = 500010;
int a[N];
int n;
long double sum;
int main() {
std::ios::sync_with_stdio(false);
cin >> n >> sum;
long double avg = sum*1.0 / n;
int clow = 0,low = 0;
double ls = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a,a+n);
long double res = 0;
long double newAvg = avg;
for (int i = 0; i < n; i++) {
if (a[i]<=newAvg){
sum-=a[i];
res+=pow(avg-a[i],2);
newAvg = sum*1.0/(n-i-1);
}else{
res+=pow(newAvg-avg,2);
}
}
printf("%.4lf", sqrt(res/n));
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liuyutaocode/cppCode.git
git@gitee.com:liuyutaocode/cppCode.git
liuyutaocode
cppCode
算法刷题c++
master

搜索帮助