A-小宋银行的贷款漏洞
PZ's solution:
1.贷款利率\(\frac{a_1}{t}\)是不变的,例如\(x=100\quad t=2\),则贷款利率为\(\frac{1}{2}\),最终连本带息须还的金额为\(100*(1+\frac{1}{2})^2=225\),所以得到\(ans=x*(1+\frac{a_1}{t})^t\);
2.对于\(t=ZERO\)的情况,会发现没有贷款利率,直接得到\(ans=x\);
3.对于\(t=+INF\)的情况,在《高等数学上册》,有一重要极限:
\[\lim_{x \to \infty} (1+\frac{1}{x})^x=e \]对于本题,当\(t\)趋近于无限时,可以发现最终答案为
\[ans=x*\lim_{t \to \infty}(1+\frac{a_1}{t})^t \]应用重要极限,得到:
\[\lim_{t \to \infty}(1+\frac{a_1}{t})^t = \lim_{t \to \infty}(1+\frac{a_1}{t})^{\frac{t}{a_1}a_1}=e^{a_1} \]则可以得到\(ans=x*e^{a_1}\)
ps.本题对\(e\)的精度有要求,代码中为最低精度,且答案向下取整;
- TAG:数学
PZ.cpp
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
#define e (double)2.71828182845904
string x,t;
long long T,res,a1;
double ans,new_ans;
int main(){
scanf("%lld",&T);
for(int j=1;j<=T;++j){
res=ans=0;
cin>>x>>t;
a1=x[0]-'0';
for(int i=0;i<x.size();++i)
ans=ans*10+x[i]-'0';
new_ans=1;
if('0'<=t[0]&&t[0]<='9'){
for(int i=0;i<t.size();++i)
res=res*10+t[i]-'0';
for(int i=1;i<=res;++i)
new_ans*=(1+a1*1.0/res*1.0);
ans=ans*new_ans;
cout<<"#Case "<<j<<" : "<<(long long)(ans)<<endl;
} else if(t=="ZERO"){
cout<<"#Case "<<j<<" : "<<x<<endl;
} else if(t=="+INF"){
for(long long i=1;i<=a1;++i)
new_ans*=e;
ans=ans*new_ans;
cout<<"#Case "<<j<<" : "<<(long long)(ans)<<endl;
}
}
return 0;
}