FZU-2264- Card Game (First Edition) - Expectation

Title:

Here is given 2*n cards, the value of each card is different, two people A and B arbitrarily choose 1 card from them, and then discard these 2 cards. one point

Now I ask you, what is the expectation of A to get the score

answer:

First we have 2*n cards, the optimal score is n->A draw the largest n cards

The worst score is 0->A draw the smallest n sheets

So for A, the expected score that A can get is (n+0) / 2


In fact, the expectation here can be regarded as the average. The probability is equal.


In summary, the code is well written:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 10000100;
bool force[maxn];
intmain()
{
    int caset,cas=0;scanf("%d",&caset);
    while(caset--)
    {
        int n;scanf("%d",&n);
        for(int i=0,x;i<2*n;i++) scanf("%d",&x);
        printf("Case %d: %.2f\n",++cas,1.0*n/2);
    }
    return 0;
}


Guess you like

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