您的位置:首页 > 其它

【腾讯马拉松3月23日】HDU 4525_威威猫系列故事——吃鸡腿

2013-03-31 14:34 204 查看
来源:点击打开链接

大水题,但是当时怎么也想不起来做的方法了。。或者说错在哪了。

公式可以通过从上往下加起来得到:a(n+1)=(k1+k2)*an,但是用__int64的话也是不行的,因为循环调用的时候会有中间数据超过__int64的范围。正解是用double,另外有一个隐含条件是k1,k2都是整数(描述中说了吗 似乎没有= =)。。这样就很容易判断inf了。。

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐