zoukankan      html  css  js  c++  java
  • 蓝桥杯入门训练

    题目:http://lx.lanqiao.cn/problemset.page?code=BEGIN-&userid=188230

    一、Fibonacci数列

    优化方法:不能直接每次求取Fibonacci递归,要用数组将原来算过的数据存储下来,因为相同的情况递归算法会重复算很多次。

    time:15ms

    #include<iostream>
    using namespace std;
    const int mod = 10007;
    int arr[1000005];
    
    int main()
    {
        arr[0] = 0;
        arr[1] = arr[2] = 1;
        for (int i = 3; i <= 1000000; ++i)
            arr[i] = (arr[i - 1] + arr[i - 2]) % mod;
        int num;
        cin >> num;
        cout << arr[num] << endl;
        return 0;
    }

    二、圆的面积

    time:15ms

    #include<iostream>
    #include<iomanip>
    using namespace std;
    
    const double PI = 3.14159265358979323;
    
    int main()
    {
        int num;
        cin >> num;
        cout << setiosflags(ios::fixed);
        cout << setprecision(7);
        cout << PI*num*num << endl;
        return 0;
    }

    三、序列求和

    公式无敌!!有公式的绝不代码模拟过程

    time:0ms

    #include<iostream>
    #include<cstdio>
    using namespace std;
    
    int main()
    {
        long long int num;
        scanf("%I64d", &num);
        long long int res = (1 + num)*num / 2;
        printf("%I64d
    ", res);
        return 0;
    }

    四、A+B问题

    #include<iostream>
    using namespace std;
    int main()
    {
        int a,b;
        cin>>a>>b;
        cout<<a+b<<endl;
        return 0;
    }
            

    感谢您的阅读,生活愉快~

  • 相关阅读:
    UOJ168. 【UR #11】元旦老人与丛林
    luogu3308,LOJ 2196 [SDOI2014]LIS
    CF1349F2. Slime and Sequences (Hard Version)
    6210. wsm
    欧拉数学习小记
    CF1508F. Optimal Encoding
    CF1508C. Complete the MST
    联合省选2021 游记
    一. Docker介绍
    Elasticsearch
  • 原文地址:https://www.cnblogs.com/lv-anchoret/p/8610250.html
Copyright © 2011-2022 走看看