1.

import java.util.Scanner;


/**
* Angewandte Mathematik, SS11
* Problem: 10491 - Cows and Cars
* Link:
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=16&page=show_problem&problem=1432
*
* @author Schramm, Felix
* @author Vogel, Johannes
* @version 1.0, 05/09/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 1.280
*/

public class Main {

public static void main (String args[]) {
Scanner input = new Scanner(System.in);
StringBuffer output = new StringBuffer();
String result = new String();
while(input.hasNextInt()){
int cows = input.nextInt();
int cars = input.nextInt();
int shows = input.nextInt();
int cowsncars = cows+cars;

result =
String.format("%.5f\n",((double)cars*(cowsncars-1)/(cowsncars*(cowsncars-1-shows))));
output.append(result);
}
System.out.print(output);

}

}

2.

/**
> * Angewandte Mathematik, SS11
> * Problem:10491 - Cows and Cars
> * Link:
> http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1432
> * @author Brielbeck, Daniel
> * @author Weber, Georg
> * @version 1.0, 05/24/2011
> * Method : Ad-Hoc
> * Status : Accepted
> * Runtime: 2.520
> */
> import java.io.BufferedReader;
> import java.io.InputStreamReader;
>
>
> public class Main {
>
> public static void main(String[] args) throws Exception {
> BufferedReader reader = new BufferedReader(new
> InputStreamReader(System.in));
> String input;
> int ncows,ncars,nshow;
> while ((input = reader.readLine()) != null)
> {
> String[] temp = input.split(" ");
> ncows=Integer.valueOf(temp[0]);
> ncars=Integer.valueOf(temp[1]);
> nshow=Integer.valueOf(temp[2]);
> System.out.printf("%.5f\n",1.0*(ncows+ncars-1)/(ncows+ncars)*ncars/((ncows+ncars)-nshow-1));
> }
> }
> }
>


3.

package am.cowsandcars;

/**
* Angewandte Mathematik, SS11
* Problem: 10491 - Cows and Cars
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=16&page=show_problem&problem=1432
*
* @author Florian Stein
* @author Franz Sommer
* @version 1.0, 05/29/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 2.092
*/

import java.text.NumberFormat;
import java.util.Locale;
import java.util.Scanner;

public class Main {

public static void main(String... args) {

Scanner sc = new Scanner(System.in);

while (sc.hasNext()) {

int nCows = sc.nextInt();

double nCars = sc.nextInt();

double nShows = sc.nextInt();

double nDoors = nCows + nCars;

// Fall 1 - Auto gewaehlt.
// chance das auto zu gewinnen bevor die tuer geoeffnet
double winCarBefore = nCars / nDoors;
// chance das auto zu gewinnen nachdem die tuere geoeffnet wurden
double winCarAfter = (nCars - 1) / (nDoors - 1 - nShows);

// carwinchance gesamt
double winCar = winCarBefore * winCarAfter;

// Fall 2 - Cow gewaehlt.
// chance die kuh zu "gewinnen" bevor die tuere geoeffnet
double winCowBefore = nCows / nDoors;
// chance das auto zu "gewinnen" nachdem die tueren geoeffnet
double winCowAfter = (nCars) / (nDoors - 1 - nShows);

// cowwinchange gesamt
double winCow = winCowBefore * winCowAfter;

// gesamt chance
double win = winCar + winCow;

// formatierung
NumberFormat n = NumberFormat.getInstance(Locale.US);

n.setMaximumFractionDigits(5);
n.setMinimumFractionDigits(5);
n.setGroupingUsed(false);

// ausgabe
System.out.println(n.format(win));

}
}

}

---------------------------------------------------------------------

1.
package contestVolumes.volume104;

import java.util.Scanner;

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 10491 - Cows and Cars
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=16&page=show_problem&problem=1432
*
* @author Siegfried Ippisch
* @version 1.0
*
* Method : -
* Status : Accepted
* Runtime: 1.872
*/
public class CowsAndCars {

public static void main(String[] args){
Scanner in = new Scanner(System.in);

while(in.hasNext()){
System.out.printf("%.5f\n",probabilityOfWinning(in.nextInt(),in.nextInt(),in.nextInt()));
}

in.close();
}

/**
* Idea:
*
* Case 1: first chose is a Car (carChance = cars/doors)
* -> remainingCars = cars - 1
* -> remianingCows = cows - show
* -> remainingDoors = doors -1 - show
* carWinChance = remainingCars/remainingDoors
*
* Case 2: first chose is a Cow (cowChance = cows/doors)
* -> remainingCars = cars
* -> remianingCows = cows - 1 - show
* -> remainingDoors = doors - 1 - show
* cowWinChance = remainingCars/remainingDoors
*
* total chance to win the car = carChance*carWinChance + cowChance*cowWinChance
*/
public static double probabilityOfWinning(double cows, double cars, double show){
double doors = cars + cows;
return (cars*(cars-1 + cows))/
(doors*(doors-1-show));
}

}