Created
September 19, 2009 23:18
-
-
Save chancancode/189629 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class E { | |
/** | |
* @param args | |
*/ | |
private static int opp; | |
private static int win; | |
private static int lose; | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
Scanner in = new Scanner(System.in); | |
int cases = in.nextInt(); | |
in.nextLine(); | |
for(int i=0;i<cases;i++){ | |
in.nextLine(); // ignore name | |
opp = in.nextInt(); | |
win = in.nextInt(); | |
lose = in.nextInt(); | |
in.nextLine(); | |
System.out.printf("%.5f\n", doWork(1.0, 20, 0, 0)); | |
} | |
} | |
static double doWork(double propSoFar, int can, int can_wins, int opp_wins){ | |
if(can_wins >= 4) | |
return propSoFar; | |
if(opp_wins >= 4) | |
return 0.0; | |
if(can <= 0) | |
return 0.0; | |
double winProp = (1.0*can) / (can + opp); | |
double loseProp = (1.0*opp) / (can + opp); | |
return doWork(propSoFar * winProp, 20 + win, can_wins + 1, opp_wins) | |
+ doWork(propSoFar * loseProp, 20 - lose, can_wins, opp_wins + 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment