题目描述及样例
详见:
https://www.acwing.com/problem/content/4512/
说明:
为方便大家阅读代码,以下代码不再使用本人常用的宏定义头文件;
思路:模拟即可
C++ 代码
#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(false);cin.tie(0),cout.tie(0)
using namespace std;
int n, a[1001];
double avg = 0, D = 0, cur_ans = 0, sigma = 0;
// 分别代表均值,方差,答案,标准差
int main(){
ios;
cin >> n;
for (int i = 1; i <= n; i++){
cin >> a[i];
avg += a[i];
}
avg /= n; // 计算均值
for (int i = 1; i <= n; i++){
D += (a[i] - avg) * (a[i] - avg);
}
D /= n; // 计算方差
sigma = sqrt(D) + 1e-9; // 计算标准差 精度修正
for (int i = 1; i <= n; i++){
cur_ans = (a[i] - avg) / sigma;
cout << setprecision(20) << fixed << cur_ans << endl;
}
return 0;
}
感谢阅读,喜欢的话不妨点个赞评论下!
祝大家天天开心