1 50.00 25.00 10.00 2 50.00 25.00 10.00 20.00
27.50 15.00思路:1-n方差两边相加,得到一个方程1-n再相加
#include <iostream> #include <stdio.h> using namespace std; int main() { double a0, an1, c; double a1; int n; while (cin>>n) { cin >> a0 >> an1; a1 = an1 + a0 * n; for (int i = 0; i < n; i++) { cin >> c; a1 -= 2 * c*(n - i); } a1 /= (n + 1); printf("%.2lf\n", a1); } return 0; }
原文:http://www.cnblogs.com/theskulls/p/6192972.html