Football
Time limit:1000 ms |
|
Memory limit:65536 K |
Total submissions:1934 |
|
Accepted:958 |
Description
Consider a single-elimination football tournament involving 2NTeams, denoted 1, 2 ,..., 2N. In each round of the tournament, all teams still in the tournament are placed in a list in order of increasing index. then, the first team in the list plays the second team, the third team plays the fourth team, etc. the winners of these matches advance to the next round, and the losers are eliminated. afterNRounds, only one team remains undefeated; this team is declared the winner.
Given a MatrixP= [Pij] Such thatPijIs the probability that teamIWill beat teamJIn a match determine which team is most likely to win the tournament.
Input
The input test file will contain multiple test cases. Each test case will begin with a single line containingN(1 ≤N≤ 7). The next 2NLines each contain 2NValues; here,JTh value onITh line representsPij. The MatrixPWill satisfy the constraints thatPij= 1.0 −PjiFor allI=J, AndPII= 0.0 for allI. The end-of-file is denoted by a single line containing the number −1. note that each of the matrix entries in this problem is given as a floating-point value. to avoid precision problems, make sure that you use eitherDouble
Data Type insteadFloat
.
Output
The output file shoshould contain a single line for each test case indicating the number of the team most likely to win. to prevent floating-point Precision issues, it is guaranteed that the difference in win probability for the top two teams will be at least 0.01.
Sample Input
20.0 0.1 0.2 0.30.9 0.0 0.4 0.50.8 0.6 0.0 0.60.7 0.5 0.4 0.0-1
Sample output
2
Hint
In the test case above, Teams 1 and 2 and teams 3 and 4 play against each other in the first round; the winners of each match then play to determine the winner of the tournament. the probability that Team 2 wins the tournament in this case is:
P (2 wins) |
=P(2 beats 1)P(3 beats 4)P(2 beats 3) +P(2 beats 1)P(4 beats 3)P(2 beats 4) =P21P34P23 +P21P43P24 = 0.9 · 0.6 · 0.4 + 0.9 · 0.4 · 0.5 = 0.396. |
The next most likely team to win is Team 3, with a 0.372 probability of winning the tournament.
Source
Stanford local 2006
Question: 2 ^ n football matches. Each team has a probability to defeat another team.
Ask which team has the highest probability of victory.
Probability DP.
Set DP [I] [J] to indicate the probability of victory for the J team in the I game.
You can draw a drawing to get the formula.
First round )''''''
It is easy to calculate.
In the second round.
For example, calculate the probability of winning 3. First, 3 is to win in the first round, and at the same time to defeat the winner (1, 2). This is the full probability formula.
/* Poj 3071 question: 2 ^ n football teams, each team has a probability to defeat another team. Ask which team has the highest probability of victory. Probability formula. You can calculate DP. */ # Include <Stdio. h> # Include <Iostream> # Include <Algorithm> # Include < String . H> Using Namespace STD; Double DP [8 ] [ 200 ]; // DP [I] [J] indicates the probability of J winning in the I-th game. Double P [ 200 ] [ 200 ]; Int Main (){ Int N; While (Scanf ( " % D " , & N )! = EOF ){ If (N =- 1 ) Break ; Memset (DP, 0 , Sizeof (DP )); For ( Int I = 0 ; I <( 1 <N); I ++ ) For (Int J = 0 ; J <( 1 <N); j ++ ) Scanf ( " % Lf " ,& P [I] [J]); // Cin> P [I] [J]; For ( Int I = 0 ; I <( 1 <N); I ++) DP [0 ] [I] = 1 ; For ( Int I = 1 ; I <= N; I ++) // 2 ^ n people need to play n games { For ( Int J = 0 ; J <( 1 <N); j ++ ){ Int T = J /( 1 <(I- 1 ); T ^ = 1 ; DP [I] [J] = 0 ; For ( Int K = T *( 1 <(I- 1 ); K <t *( 1 <(I- 1 ) + ( 1 <(I- 1 ); K ++ ) DP [I] [J] + = DP [I- 1 ] [J] * DP [I- 1 ] [K] * P [J] [k] ;}} Int Ans; Double Temp = 0 ; For ( Int I =0 ; I <( 1 <N); I ++ ){ If (DP [N] [I]> Temp) {ans = I; temp = DP [N] [I] ;}} printf ( " % D \ n " , ANS + 1 );} Return 0 ;}