码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 5139 Formula

时间:2015-01-14 19:56:01      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:

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

思路:这道题要先找规律,f(n)=n!*(n-1)!*(n-2)!.....1!;  不能直接打表,而是离线处理,一次性处理出来。

技术分享
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <map>
 4 #include <algorithm>
 5 #define ll long long
 6 #define mod 1000000007
 7 #define N 100010
 8 using namespace std;
 9 
10 ll n;
11 struct node
12 {
13     ll c,id,m;
14     bool operator <(const node &a)const
15     {
16         return id<a.id;
17     }
18 }p[N];
19 bool cmp1(node a,node b)
20 {
21     return a.c<b.c;
22 }
23 
24 int main()
25 {
26     int t1=0;
27     while(scanf("%lld",&n)!=EOF)
28     {
29         p[t1].c=n;
30         p[t1].id=t1;
31         t1++;
32     }
33     sort(p,p+t1,cmp1);
34     ll s=1;
35     ll ans=1;
36     int cnt=0;
37     for(int x=1; x<=p[t1-1].c; x++)
38     {
39         s=s*x%mod;
40         ans=ans*s%mod;
41         while(cnt<t1&&p[cnt].c==x)
42         {
43             p[cnt].m=ans;
44             cnt++;
45         }
46     }
47     sort(p,p+t1);
48     for(int i=0; i<t1; i++)
49     {
50         printf("%lld\n",p[i].m);
51     }
52     return 0;
53 }
View Code

 

hdu 5139 Formula

标签:

原文地址:http://www.cnblogs.com/fanminghui/p/4224679.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!