CCF-CSP试题202206-1归一化处理题解

202206-1归一化处理

题解:

#include
#include
using namespace std;

int main() {
	int n, p[1000], sum = 0;
	cin >> n;
	for(int i=0; i<n; i++) {
		cin >> p[i];
		sum += p[i];
	}
	double x = (double) sum / n;
	double d = 0;
	for(int i=0; i<n; i++) {
		double y = (double)p[i] - x; 
		d += y * y;
	}
	d = sqrt(d / n);
	double a[1000];
	for(int i=0; i<n; i++) {
		a[i] = ((double)p[i] - x) / d;
		cout << a[i] << endl;
	}
	return 0;
}

你可能感兴趣的:(CCF-CSP,c++,算法,图论)