Connection Status:
Competition Arena > TheFansAndMeetingsDivOne
SRM 460 · 2009-11-12 · by Vasyl[alphacom] · Dynamic Programming, Simple Math
Class Name: TheFansAndMeetingsDivOne
Return Type: double
Method Name: find
Arg Types: (vector<int>, vector<int>, vector<int>, vector<int>, int)
Problem Statement

Problem Statement

John and Brus have become very famous people all over the world, especially in Bolivia. Stories written about them by a Bolivian man have become very popular in that country. John and Brus have decided to visit their fans in Bolivia, but unfortunately, they only have time to visit k cities each.

John will randomly choose k distinct cities. Each set of k cities has the same probability of being chosen. If he chooses the i-th city, he will meet between minJ[i] and maxJ[i] fans there, inclusive. Each possible number of fans is equally likely. Brus will go through the exact same process, but in his case, the number of fans he would meet in the i-th city is between minB[i] and maxB[i], inclusive. Return the probability that John and Brus will each meet the same total number of fans.

Notes

  • The returned value must be accurate to within a relative or absolute value of 1E-9.

Constraints

  • minJ will contain between 1 and 40 elements, inclusive.
  • minJ, maxJ, minB and maxB will contain the same number of elements.
  • Each element of minJ, maxJ, minB and maxB will be between 1 and 40, inclusive.
  • The i-th element of minJ will be less than or equal to the i-th element of maxJ.
  • The i-th element of minB will be less than or equal to the i-th element of maxB.
  • k will be between 1 and the number of elements in minJ, inclusive.
Examples
0)
{1}
{9}
{5}
{5}
1
Returns: 0.1111111111111111

Brus will definitely meet five fans, and the probability of John meeting five fans as well is 1/9.

1)
{5, 2, 5, 1, 1, 2, 4, 1}
{7, 6, 7, 3, 4, 3, 5, 1}
{8, 9, 7, 11, 12, 7, 8, 40}
{9, 10, 9, 33, 14, 7, 11, 40}
2
Returns: 4.724111866969009E-5

The only possible same total number of fans that John and Brus can meet is 14. In order for them to meet 14 fans, John must visit cities 0 and 2 and Brus must visit cities 2 and 5. In each of these cities they must meet exactly 7 fans.

2)
{4, 7, 4}
{7, 7, 7}
{40, 40, 40}
{40, 40, 40}
1
Returns: 0.0

No chance to meet the same number of fans.

3)
{3, 6, 2, 1, 1, 10, 3}
{6, 9, 5, 6, 5, 10, 9}
{1, 1, 1, 1, 8, 3, 1}
{3, 9, 7, 3, 10, 6, 5}
4
Returns: 0.047082056525158976
4)
{1}
{7}
{3}
{3}
1
Returns: 0.14285714285714285

Submissions are judged against all 65 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class TheFansAndMeetingsDivOne with a public method double find(vector<int> minJ, vector<int> maxJ, vector<int> minB, vector<int> maxB, int k) · 65 test cases · 2 s / 256 MB per case

Submitting as anonymous