您的位置:首页 > 其它

hdu_2044_一只小蜜蜂...(递推专题)

2014-12-14 16:48 411 查看
<a target=_blank href="http://acm.hdu.edu.cn/showproblem.php?pid=2044">http://acm.hdu.edu.cn/showproblem.php?pid=2044</a>
/*从1到3 和 从2到3的方法不同*/
#include <iostream>
using namespace std;
long long a[51];

//打表
void fac()
{
a[1] = 1;
a[2] = 2;
long long a1 = 1;
long long a2 = 2;
for(int i = 3;i < 50;i++)
{
a[i] = a1 + a2;
a1 = a2;
a2 = a[i];
}
}
long long f(int x,int y)
{
int result = y - x;
return a[result];
}
int main(int argc, char *argv[])
{
fac();
int s;
cin >> s;
while(s--)
{
int x,y;
cin >> x >> y;
if(x >= y)
{
cout << 0 << endl;
continue;
}

if(x % 2 != 0)
{
cout << f(1,y-x+1) << endl;
}
else
{
cout << f(2,y-x+2) << endl;
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: