2018 蓝桥杯省赛 B 组模拟赛(一)数列求值(附推导过程)
题面链接:https://nanti.jisuanke.com/t/20688
网上的博客很多都没有详细推导过程,特意写一下我的。
#include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<algorithm> #include<iostream> #include<queue> #include<map> #include<cmath> #include<set> #include<stack> #define ll long long #define pb push_back #define max(x,y) ((x)>(y)?(x):(y)) #define min(x,y) ((x)>(y)?(y):(x)) #define cls(name,x) memset(name,x,sizeof(name)) #define fs first #define sc second #define mp make_pair #define L(x) (1<<x) #define next Next #define index Index using namespace std; const int inf=1e9+10; const ll llinf=1e17+10; const int maxn=1e3+10; const int maxm=25e2+10; const int mod=1e9+7; int n; double A0,Ana1; double C[maxn]; double sumC[maxn]; int main() { //freopen("in.txt","r",stdin); while(~scanf("%d",&n)) { scanf("%lf %lf",&A0,&Ana1); fill(sumC,sumC+maxn,0.0); for(int i=1;i<=n;i++) { scanf("%lf",&C[i]); sumC[i]=sumC[i-1]+C[i]; } double d1; double t=0; for(int i=1;i<=n;i++) { t+=2.0*sumC[i]; } d1=(Ana1-A0-t)/(n+1); printf("%.2lf\n",d1+A0); } return 0; }