hdu2086-A1 = ?

http://acm.hdu.edu.cn/showproblem.php?pid=2086

推出公式为(  n + 1 )  *  a1 + 2 * ( c1 + c1+c2+cq+c2+c3+......+cn) = n * a0 + an 

 

#include "stdio.h"

#include "string.h"

#include "stdlib.h"

#include "math.h"

#include "algorithm"

#include "iostream"



using namespace std;



int main()

{

	int n , i , j ; 

	double a0 , an ,c[ 3005 ] ,temp ,sum1 ,sum;

	while( ~scanf( "%d" , &n ) )

	{

		scanf( "%lf" ,&a0 ) ;

		scanf( "%lf", &an ) ;

		sum1 = sum = 0 ;

		for(  i = 1 ; i <= n ; i++ )

		{

			scanf( "%lf" , &temp) ;

			sum1 += temp ;

			sum += sum1 * 2.0 ;

		/*	scanf( "%lf" ,&c[ i ] ) ;

		double temp = 0.0 ;

		for(  i = 1 , j = n ; i <= n ; i++ ,j-- )

		{

			temp +=  i * c[ j ] ;

		}

		temp = 2.0 * temp ;*/

		}

		printf( "%.2lf\n" , 1.0 * ( ( 1.0 * n * a0 + an ) - sum ) /( 1.0 *( n + 1 ) ) ) ;

	}

	return 0;

}


 

 

你可能感兴趣的:(HDU)