Skip to content

Instantly share code, notes, and snippets.

@chancancode
Created September 19, 2009 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chancancode/189629 to your computer and use it in GitHub Desktop.
Save chancancode/189629 to your computer and use it in GitHub Desktop.
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