"Turn" hdu-2048-God, God, and heaven: Wrong row

Source: Internet
Author: User
Tags natural logarithm

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.