Description
有一长度为n+2的序列a[0],a[1],…a[n+1]满足a[i]=(a[i-1]+a[i+1])/2-c[i],i=1,2,…n,现给出a[0],a[n+1],c[1],…c[n],求a[1]
Input
第一行为一整数n,之后为n+2个整数a[0],a[n+1],c[1],…,c[n]
Output
输出a[1]
Sample Input
1
50.50
25.50
10.15
Sample Output
27.85
Solution
简单数列题
Code
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define maxn 3333
int n;
double a,b,c,ans,sum;
int main()
{
while(~scanf("%d",&n))
{
scanf("%lf%lf",&a,&b);
sum=0;
for(int i=0;i<n;i++)
{
scanf("%lf",&c);
sum+=(n-i)*c;
}
ans=(n*a+b-2*sum)/(n+1);
printf("%.2lf\n",ans);
}
return 0;
}