【Number Theory】【HDU 2048】God, God and God

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

I didn't expect that I was really happy and found my blind spot. In fact, I saw this question when I was a freshman, but I skipped it at that time.

Fate, amazing~

Derangement formula

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 #define ll long long
 6 #define max3(a,b,c) fmax(a,fmax(b,c))
 7 #define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 8 
 9 int main()
10 {
11     ll a[22];
12     a[0] = 0;
13     a[1] = 0;
14     a[2] = 1;
15     for(int i = 3;i <= 20;i++)
16     {
17         a[i] = (i-1)*(a[i-1] + a[i-2]);
18     }
19     int c,temp;
20     cin >> c;
21     while(c--)
22     {
23         scanf("%d",&temp);
24         ll s = 1;
25         for(int i = 1;i <= temp;i++)
26         {
27             s *= i;
28         }
29         printf("%.2lf%%\n",(double)(a[temp]*1.0)*100.0/s);
30     }
31     
32     return 0;
33 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325027786&siteId=291194637