标签:style blog http io ar color os sp for
题目链接:
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]); }
标签:style blog http io ar color os sp for
原文地址:http://blog.csdn.net/bigbigship/article/details/41864121