SOJ-2857(数学递推公式)

/******************************************************************************************************
 ** Copyright (C) 2011.07.01-2013.07.01
 ** Author: famousDT <[email protected]>
 ** Edit date: 2011-07-17
******************************************************************************************************/
#include <stdio.h>
#include <stdlib.h>//abs,atof(string to float),atoi,atol,atoll
#include <math.h>//atan,acos,asin,atan2(a,b)(a/b atan),ceil,floor,cos,exp(x)(e^x),fabs,log(for E),log10
#include <vector>
#include <queue>
#include <map>
#include <time.h>
#include <set>
#include <stack>
#include <string>
#include <iostream>
#include <assert.h>
#include <string.h>//memcpy(to,from,count
#include <ctype.h>//character process:isalpha,isdigit,islower,tolower,isblank,iscntrl,isprll
#include <algorithm>
using namespace std;

//typedef long long ll;

#define PI acos(-1)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MALLOC(n, type) ((type *)malloc((n) * sizeof(type)))
#define FABS(a) ((a) >= 0 ? (a) : (-(a)))
#define MAX_INT 0xfffffff

/***********************************解题报告*******************************************
 ** a1 = (a0 + a2) / 2 -c1    ->    2 * a1 = a0 + a2 - 2 * c1
 ** a2 = (a1 + a3) / 2 -c2    ->    2 * a2 = a1 + a3 - 2 * c2
 ** a3 = (a2 + a4) / 2 -c3    ->    2 * a3 = a2 + a4 - 2 * c3
 ** ……    ……    ……
 ** an = (an-1 + an+1) / 2 -cn    ->    2 * an = an-1 + an+1 - 2 * cn
 ** 保留第一行,并从第一个式子往下加
 ** 2 * a1 = a0 + a2 - 2 * c1
 ** a1 + a2 = a0 + a3 - 2 * (c1 + c2)
 ** a1 + a3 = a0 + a4 - 2 * (c1 + c2 + c3)
 ** ……    ……    ……
 ** a1 + an = a0 + an+1 - 2 * (c1 + c2 + c3 + c4 + … + cn)
 ** n个式子相加,得
 ** (n + 1) * a1 = n * a0 + an+1 - 2 * (n * c1 + (n - 1) * c2 + (n - 2) * c3 + … + cn)
****************************************************************************************/

int main()
{
    int n;
    int i;
    double a, b;
    while (scanf("%d", &n) == 1) {
        scanf("%lf%lf", &a, &b);
        double ans, c;
        ans = n * a + b;
        for (i = 1; i <= n; ++i) {
            scanf("%lf", &c);
            ans -= 2 * (n - i + 1) * c;
        }
        printf("%.2lf\n", ans / (n + 1));
    }
    return 0;
}


 

你可能感兴趣的:(c,Date,String,float)