【腾讯马拉松3?3日?HDU 4525_威威猫系列故事?—吃鸡腿
来源Q?a href="http://acm.hdu.edu.cn/showproblem.php?pid=4525">点击打开链接
大水题,但是当时怎么也想不v来做的方法了。?或?说错在哪了?
公式可以通过从上?加v来得刎ͼa(n+1)=(k1+k2)*anQ但是用__int64的话也是不行的,因ؓ循环调用的时候会有中间数据超过__int64的范围?正解是用double,另A有一个隐含条件是k1,k2都是整数(描述中说了吗 似乎没? =)。?这样很Ҏ判断inf了??/p>
#include <iostream>#include <cstring>using namespace std;int main(){double res,k1,k2,notbig;int testcase;cin>>testcase;for(int a=1;a<=testcase;a++){res=0;int orgn;double temp;int count=0;cin>>orgn>>k1>>k2>>notbig;for(int i=0;i<orgn;i++){cin>>temp;res+=temp;}if(res>notbig){cout<<"Case #"<<a<<": "<<0<<endl;}else if(k1+k2>=-1 && k1+k2<=1){cout<<"Case #"<<a<<": "<<"inf"<<endl;}else{while(res<=notbig){res*=(k1+k2);count++;}cout<<"Case #"<<a<<": "<<count<<endl;}}return 0;}