Take Your Seat+计蒜课

Duha decided to have a trip to Singapore by plane.

The airplane had n seats numbered from 1 to nn, and n passengers including Duha which were also counted from 1 to nn.The passenger with number i held the ticket corresponding to the seat with number i, and Duha was the number 1 passenger.

All passengers got on the plane in the order of their numbers from 1 to nn.However, before they got on the plane Duha lost his ticket (and Duha was the only passenger who lost the ticket), so he could not take his seat correctly.He decided to take a seat randomly.And after that, while a passenger got on the plane and found that his/her seat has been occupied, he/she selected an empty seat randomly as well.A passenger except Duha selected the seat displayed in his/her ticket if it had not been occupied by someone else.

The first problem you are asked to calculate in this problem is the probability of the last passenger to get on the plane that took his/her correct seat.

Several days later, Duha finished his travel in Singapore, and he had a great time.

On the way back, he lost his ticket again.And at this time, the airplane had mm seats numbered from 1 to mm, and mm passengers including Duha which were also counted from 1 to mm.The passenger with number ii held the ticket corresponding to the seat with number ii, and Duha was the number 1 passenger as well.

The difference was that: all passengers got on the plane in a random order (which was any one of the m!m! different orders with the same chance).Similarly, Duha or a passenger who found his/her seat had been occupied selected an empty seat randomly.

The second problem you are asked to calculate in this problem is the probability of the last passenger to get on the plane that took his/her right seat on the return trip.

Input Format

The input contains several test cases, and the first line is a positive integer T indicating the number of test cases which is up to 50.

For each test case, a line contains two integers n and m~(1\le n, m\le 50)m (1≤n,m≤50).

Output Format

For each test case, output a line containing Case #x: y z, where xx is the test case number starting from 1, yy is the answer of the first problem, and z is the answer of the second problem.Both of y and z are rounded to 66places, and we guarantee that their 7-th places after the decimal point in the precise answer would not be 4 or 5.

样例输入

1
2 3

样例输出

Case #1: 0.500000 0.666667

AC代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,T;
    cin >> T;
    int k=1;
    while(T--){
        cin >> n >>m;
        cout << "Case #" << k <<": ";
        k++;
        if(n==1)
            cout << "1.000000";
        else
            cout << "0.500000";
            printf(" %0.6lf\n",(double)(m+1)/(m*2));
	}
    return 0;
}

猜你喜欢

转载自blog.csdn.net/blackneed/article/details/81131283