找规律写出来WA掉了,思前想后找不到原因。
后来,发现数组要是LL的。。。。
用递归就好,第11页上不少这样的题。都是找规律用递归
/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
LL m[50 + 24];
void init() {
int i;
m[0] = 1, m[1] = 1, m[2] = 2;
for(i = 3; i < 74; i++)
m[i] = m[i-1] + m[i-2];
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int n, a, b;
cin >> n;
init();
while(n--) {
cin >> a >> b;
cout << m[b-a] << endl;
}
return 0;
}
/**/
博主做找规律题时提交结果WA,找不到原因,后来发现数组需为LL类型。还提到此类找规律题用递归解决即可,第11页有不少这样的题目。
1800

被折叠的 条评论
为什么被折叠?



