这题又是一题递推的水题,从反面来考虑舒服多。
一开始没有经过站点时有3个,每经过一个站点就减一个后加倍。
可以提取公式f(n)=2*(f(n-1)-1)
将其化成通项公式,提升程序效率。
f(n)=2^n+2
贴代码
#include<stdio.h>
#include<math.h>
int main()
{
__int64 x;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&x);
x=(__int64)pow((float)2,(int)x)+2;
printf("%I64d\n",x);
}
return 1;
}