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
  • 相关阅读:
    设置内存管理
    Kill Session
    设置In_Memery
    查询无效对象 及 重新编译
    Oracle 硬解析查询
    设置Oracle 12C OEM 端口
    创建Mysql 序列
    compress 表设置及索引设置
    闪回表
    ECS Samples概述
  • 原文地址:https://www.cnblogs.com/whatbeg/p/4148866.html
Copyright © 2011-2022 走看看