HDU5139 Formula (找规律+离线处理)

题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=5139


分析:

直接暴力求很明显会超时,因此我们想到了打表但是把表打下来发现超内存了,由于数据有从小到大递推的关系,

可以对数据进行离线处理,排好序之后从小到大暴力即可


代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;

typedef long long LL;

const int mod = 1000000007;

const int maxn = 100000;

struct nod{
    int id,n;
    bool operator <(const struct nod &tmp) const{
        if(n==tmp.n)
            return id < tmp.id;
        return n<tmp.n;
    }
}a[maxn];

LL ans[maxn];

int main()
{
    int cnt=0,n;
    //freopen("out.txt","w",stdout);
    while(~scanf("%d",&n)){
        a[cnt].id = cnt;
        a[cnt++].n = n;
    }
    sort(a,a+cnt);
    LL tmp = 1, tans = 1,j = 1;
    for(int i = 0;i < cnt; i++){
        for(;j <= a[i].n;j++){
            tmp = tmp*j%mod;
            tans = tans*tmp%mod;
        }
        ans[a[i].id]=tans;
    }
    for(int i=0;i<cnt;i++)
        printf("%lld\n",ans[i]);
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值