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
  • 相关阅读:
    如何完全删除Linux应用
    IP地址获取工具类
    日期处理工具类
    Cookies的工具类
    权限管理系统学习笔记
    SpringBoot中JPA的一些基本操作
    Mysql和Java的数据类型对应表
    MySQL中的tinyint
    幂等性浅谈
    链接
  • 原文地址:https://www.cnblogs.com/whatbeg/p/4148866.html
Copyright © 2011-2022 走看看