10014 - Simple calculations

题目:10014 - Simple calculations


题目大意:挺好理解的理解就不说了;

解题思路:公式:(n+1)*a1 = n*a0 + a(n+1) - 2*cn - 4*c(n-1)- ……-2*n*c1;感觉会相乘相加会蛮大的,就用double ,比较保险。


#include<stdio.h>

int t, n;
double a, b;
const int N = 3005;
double s[N];

int main() {

	scanf("%d", &t);
	while(t--) {
		int i;
		scanf("%d", &n);
		scanf("%lf %lf", &a, &b);
		for( i = 0; i < n; i++)
			scanf("%lf", &s[i]);
	
		double sum = 0;
		int k = 2;
		for(i = 0; i < n ; i++)
			sum += k * (n - i)*s[i];
		sum = n * a + b - sum;
		printf("%.2lf\n", sum / (n + 1));
		if(t)
			printf("\n");
	}
	return 0;
}


你可能感兴趣的:(10014 - Simple calculations)