Error-Line Simplification formula:
D (n) = [n!/e+0.5] where E is the base of the natural logarithm, [x] is the integer part of X
#include <iostream> #include <cmath> #include <iomanip> #include <cstdio>using namespace std; Const double E=EXP (1);//E 1-Time Square int main () { double arr[21], tmp=1.0; int T, n, I; for (int i=2; i<21; i++) { tmp*=i; Arr[i]=round (tmp/e)/tmp;//round function returns rounding integer value } scanf ("%d", &t); while (t--) { scanf ("%d", &n); printf ("%.2f%%\n", arr[n]*100.0); } return 0;}
All possible permutations of the n note are naturally n! (denominator).
Now the problem is to ask for N-note the number of rows f (n) (molecule).
First of all we consider that if the front N-1 people are not their own votes, that is, the former N-1 individual satisfied the wrong row, now another person, he is holding his own ticket. As long as he exchanged his ticket with any of the other N-1 individuals, he would be able to satisfy the N-man's Wrong row. At this time there are (N-1) *f (N-1) methods.
#include <iostream> #include <string> #include <iomanip>using namespace Std;int main () { double arr[21]={0, 0, 1}; for (int i=3; i<21; i++) { arr[i]= (arr[i-1]+arr[i-2]) * (i-1); } int t; cin>>t; while (t--) { int n; cin>>n; Double tmp=1; for (int i=2; i<=n; i++) tmp*=i; Cout<<fixed<<setprecision (2) << (arr[n]/tmp) *100.0<< "%" <<endl; } return 0;}
"Turn" hdu-2048-God, God, and heaven: Wrong row