问题标题: 酷町堂:1148 555......

0
0

0
已采纳
江齐悦
江齐悦
高级光能
高级光能

这位大佬您好!

以下是主函数代码,还有一些自己想一想,不行的话在评论区跟我说。

或者发一下错误代码谢谢。

int main(){
    len[1]=1,len[2]=2;
    a[1]=a[2]=1;
    for(int i=3;i<=91;i++)
    {
        len[i]=len[i-1]+len[i-2];
        a[i]=a[i-1]+a[i-2];
    }
    cin>>q;
    while(q--){
        cin>>m>>n;
        cout<<cal(n,91)-cal(m-1,91)<<endl;
    }
}

最后,望采纳,谢谢

0
0
0
李明阳
李明阳
初级光能
初级光能

#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize(2)

加上这个火车头    

0
张恩泽
张恩泽
高级天翼
高级天翼

这题的函数可以用递做:

long long 函数名 (long long 形参) {
    if (形参 == 0) {
        return 0;
    }
    定义i = 1
    while (len[i] <= 形参) {
        i ++;
    }
    return a[i-1] + cal (形参 - len[i-1]);
}

主函数部分:

len[1] = 1, len[2] = 2;
a[1] = 1, a[2] = 1;
for (i从3循环到91){
    len[i] = len[i-1] + len[i-2];
    a[i] = a[i-1] + a[i-2];
}
输入q
for (i从1开始,循环q次) {
    输入x, y
    cout << cal (y) - cal (x-1) << endl;
}

 

我要回答