标签:style blog http color io os ar for sp
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=955
根据递推公式推倒出a1的公式。
a1=(n*a0+an+1-2*(n*c1+(n-1)*c2+...+cn))/(n+1);
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #define maxn 50000 5 using namespace std; 6 7 double a1,a2; 8 double c[maxn]; 9 int t; 10 int n; 11 12 int main() 13 { 14 scanf("%d",&t); 15 while(t--) 16 { 17 scanf("%d",&n); 18 scanf("%lf%lf",&a1,&a2); 19 double sum=n*a1+a2; 20 for(int i=1; i<=n; i++) 21 { 22 scanf("%lf",&c[i]); 23 sum-=2.0*(n+1-i)*c[i]; 24 } 25 printf("%.2lf\n",sum/(n+1)); 26 if(t!=0) printf("\n"); 27 } 28 return 0; 29 }
标签:style blog http color io os ar for sp
原文地址:http://www.cnblogs.com/fanminghui/p/4019886.html