杭电2086,数学归纳法
Ai = (Ai-1 + Ai+1)/2 – Ci (i = 1, 2, 3, …. n). 用A5做示范,就能猜测出公式来。证明方法可以采用数学归纳法。这里证明从略。
A5= (A4+ A6) / 2 – C5
A4= (A3+ A5) / 2 – C4= A3/ 2 + A4/ 4 + A6/ 4 – C5/ 2 – C4
=>A4= 2A3/3 + A6/3 – 2C5/3 – 4C4/3
A3= (A2+ A4) / 2 – C3= A2/ 2 + A3/ 3 + A6/ 6 – C5/ 3 – 2C4/ 3 – C3
=>A3= 3A2/4 + A6/4 – C5/2 – C4- 3C3/2
A2= (A1+ A3) / 2 – C2= A1/ 2 + 3A2/ 8 + A6/ 8 – C5/ 4 – C4/ 2 – 3C3/ 4 – C2
=>A2= 4A1/5 + A6/5 – 2C5/5 – 4C4/5 – 6C3/5 – 8C2/5
A1= (A0+ A2) / 2 – C1= A0/ 2 + 2A1/ 5 + A6/ 10 – C5/ 5 – 2C4/ 5 – 3C3/ 5 – 4C2/ 5 – C1
=>A1= 5A0/6 + A6/6 – C5/3 – 2C4/3 – C3- 4C2/3 – 5C1/3
算到这里,我想你已经总结出公式了:
A1 = (n * A0+ An+1- 2 * Cn- 4 * Cn-1- … – 2 * i * Cn-i+1- 2 * n * C1) / (n + 1)
#include<stdio.h>
int main()
{
int n,i,j;
double a1,x,y,c[3005];
while(scanf(“%d”,&n)!=EOF)
{
scanf(“%lf%lf”,&x,&y);
for(i=1;i<=n;i++)
scanf(“%lf”,c+i);
a1=n*x+y;
for(i=n;i>0;i–)
{
a1-=2*i*c[n-i+1];
}
printf(“%.2lf\n”,a1/(n+1));
}
}