zoukankan      html  css  js  c++  java
  • HDU 5139 Formula --离线处理

    题意就不说了,求公式。

    解法: 稍加推导能够得出 : f(n) = n! * f(n-1) , 即其实是求: ∏(n!)  ,盲目地存下来是不行的,这时候看见条件: 数据组数 <= 100000, 那么我们可以离线做,先把他们存下来,然后再从小到大扫一边, 也就是最多10000000次乘法的复杂度。然后离线输出即可。

    代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #define Mod 1000000007
    #define ll long long
    using namespace std;
    #define N 100002
    
    ll ans[N];
    struct node {
        int n,ind;
    }a[N];
    
    int cmp(node ka,node kb) { return ka.n < kb.n; }
    
    int main()
    {
        int tot = 0,i,n;
        while(scanf("%d",&n)!=EOF)
        {
            a[++tot].n = n;
            a[tot].ind = tot;
        }
        sort(a+1,a+tot+1,cmp);
        ll fac = 1, f = 1;
        int j = 1;
        for(i=1;i<=tot;i++)
        {
            while(j <= a[i].n)
            {
                fac = fac*j%Mod;
                f = f*fac%Mod;
                j++;
            }
            ans[a[i].ind] = f;
        }
        for(i=1;i<=tot;i++)
            cout<<ans[i]<<endl;
        return 0;
    }
    View Code
  • 相关阅读:
    SQL优化
    Mybatis
    Spring MVC(总结二)
    ES多机集群配置
    ES索引,分片,一致性
    ElasticSearch关于索引库的命令操作
    试题01(一)
    Linux安装配置elastic search
    Windows安装配置elastic search
    SpringBoot(二)
  • 原文地址:https://www.cnblogs.com/whatbeg/p/4148866.html
Copyright © 2011-2022 走看看