我的思路: 计算平均值 --> 计算方差 --> 根据公式计算f(ai)值
我的题解:100分
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main() {
int n;
cin >> n;
int a[n+1];
// a_avg_temp: a1+a2+...+ai的和
double a_avg_temp = 0;
for(int i = 1; i < n + 1; i++) {
cin >> a[i];
a_avg_temp += a[i];
}
// a_avg:平均值
double a_avg = 0;
// a_fc_temp: pow(a[1]-平均值, 2)+pow(a[2]-平均值, 2)+...+pow(a[i]-平均值, 2)的和
a_avg = a_avg_temp / n;
double a_fc_temp = 0, a_fc = 0;
for(int i = 1; i < n + 1; i++) {
a_fc_temp += pow(a[i]-a_avg, 2);
}
a_fc = a_fc_temp / n;
for(int i = 1; i < n + 1; i++) {
double f = 0;
f = (a[i] - a_avg) / sqrt(a_fc);
printf("%.16lf\n", f);
}
return 0;
}