zoukankan      html  css  js  c++  java
  • 2019牛客暑期多校训练营(第一场)- B Integration

    积分

    数字太多不好计算,可以先看看比较简单的几种情况:

    n = 1时,可以直接积分出来,答案是 1/2a

    n = 2时,我们把原式展开,拆成两个分数相加的形式,用待定系数法解出分子,然后发现可以转化成两个n=1的情况相加

    n = 3时,还是和上面一样的方法,死算。

    最后发现通式为:

    (sum_{i=1}^nfrac{1}{2*a_i}prod_{i=1}^nfrac{1}{a_j^2-a_i^2})

    然后O(n^2)算就好了

    #include <bits/stdc++.h>
    #define INF 0x3f3f3f3f
    #define full(a, b) memset(a, b, sizeof a)
    #define FAST_IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
    using namespace std;
    typedef long long ll;
    inline int lowbit(int x){ return x & (-x); }
    inline int read(){
        int ret = 0, w = 0; char ch = 0;
        while(!isdigit(ch)) { w |= ch == '-'; ch = getchar(); }
        while(isdigit(ch)) ret = (ret << 3) + (ret << 1) + (ch ^ 48), ch = getchar();
        return w ? -ret : ret;
    }
    inline int gcd(int a, int b){ return b ? gcd(b, a % b) : a; }
    inline int lcm(int a, int b){ return a / gcd(a, b) * b; }
    template <typename T>
    inline T max(T x, T y, T z){ return max(max(x, y), z); }
    template <typename T>
    inline T min(T x, T y, T z){ return min(min(x, y), z); }
    template <typename A, typename B, typename C>
    inline A fpow(A x, B p, C lyd){
        A ans = 1;
        for(; p; p >>= 1, x = 1LL * x * x % lyd)if(p & 1)ans = 1LL * x * ans % lyd;
        return ans;
    }
    
    const int N = 2000;
    const int MOD = 1e9 + 7;
    int n;
    ll a[N];
    
    int main(){
    
        while(~scanf("%d", &n)){
            for(int i = 1; i <= n; i ++) scanf("%lld", &a[i]);
            ll ans = 0;
            for(int i = 1; i <= n; i ++){
                ll t = 2 * a[i] % MOD;
                for(int j = 1; j <= n; j ++){
                    if(i == j) continue;
                    t = t % MOD * ((a[j] * a[j] % MOD + MOD - a[i] * a[i] % MOD) % MOD) % MOD;
                }
                ans = (ans % MOD + fpow(t, MOD - 2, MOD)) % MOD;
            }
            printf("%lld
    ", ans);
        }
        return 0;
    }
    
  • 相关阅读:
    Numpy用于数组的文件输入输出
    numpy利用数组进行数据处理
    numpy的通用函数:快速的元素级数组函数
    NumPy基础知识:数组和矢量计算
    数据处理任务介绍
    Django的ModelForm
    Http1.0和Http1.1的主要区别
    静态库中如何包含资源文件
    zt 正则
    oc调用swift的打包.a / framework 不成功?!
  • 原文地址:https://www.cnblogs.com/onionQAQ/p/11211921.html
Copyright © 2011-2022 走看看