d[i]a[i]res[i]
01.000000
Case1:0.5000002.0000001.000000
Case2:0.3750002.7500001.500000
Case3:0.3125003.3750002.000000
Case4:0.2734383.9218752.375000
Case5:0.2460944.4140632.750000
Case6:0.2255864.8652343.062500
Case7:0.2094735.2841803.375000
Case8:0.1963815.6769413.648438
Case9:0.1854716.0478823.921875
Case10:0.1761976.4002764.167969
Case11:0.1681886.7366524.414063
Case12:0.1611807.0590134.639648
Case13:0.1549817.3689754.865234
Case14:0.1494467.6678675.074707
Case15:0.1444647.9567965.284180
Case16:0.1399508.2366965.480560
Case17:0.1358348.5083635.676941
Case18:0.1320618.7724845.862411
Case19:0.1285859.0296556.047882
Case20:0.1253719.2803966.224079
易发现,偶数的res[i]=(res[i-1]+res[i+1])/2
故只要知道奇数位的值即可。抽象成序列a[i]。相邻两项做差,抽象出d[i]序列。
化为分数,相邻两项做商,发现d[i]=d[i-1]*(2*i-1)/(2*i)。
不一定要用整数来找规律,可以试试分数。或许会有意外的收获哦。
嗨,还是做题少,缺乏这眼力和灵感。人家3分钟发现的规律啊。。。。
**********************************************SourceCode:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
usingnamespacestd;
constintmaxn=1510;
doublea[maxn],d[maxn];
voidgetd()
{
d[1]=0.5;
for(inti=2;i<maxn;i++)
d[i]=d[i-1]*(2*i-1)/(2*i);
}
voidgeta()
{
a[0]=1.0;
for(inti=1;i<maxn;i++)
a[i]=a[i-1]+2*d[i];
}
intmain()
{
getd();
geta();
intt,ca=1,n;
scanf("%d",&t);
while(t-->0)
{
scanf("%d",&n);
printf("Case%d:",ca++);
if(n&1)
printf("%.6lfn",a[n/2]);
else
printf("%.6lfn",(a[(n-1)/2]+a[(n+1)/2])*0.5);
}
return0;
}