累加法

#include <stdio.h>
int main(){
double a_1,a_0,a_n_1,sum,c;
int i,t,n,k;
while(scanf("%d",&t)==1){
while(t--){
scanf("%d%lf%lf",&n,&a_0,&a_n_1);
sum=n*a_0+a_n_1;
for(i=0;i<n;i++){
scanf("%lf",&c);
sum-=2*(n-i)*c;
}
printf("%.2lf\n",sum/(n+1));
if(t)
putchar('\n');
}
}
return 0;
}
用数学公式推,累加法
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=12&problem=955&mosmsg=Submission+received+with+ID+11322444

posted @ 2013-02-28 18:56  L kill  阅读(294)  评论(0编辑  收藏  举报