hdu 5139 Formula

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

 

转载于:https://www.cnblogs.com/fanminghui/p/4224679.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值