首页 > 其他 > 详细

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

时间:2014-12-11 12:22:53      阅读:256      评论:0      收藏:0      [点我收藏+]

题目链接:

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]);
}


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

原文:http://blog.csdn.net/bigbigship/article/details/41864121

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!