UVA10056




Sample Input:
2
2 0.166666 1
2 0.166666 2

Sample Output:
0.5455
0.4545



大意: 給一個骰子 要你求第N個人在規定條件下贏的機率

ex: 骰到1贏 (機率是1/6)

解法: 分母為幾個人輸的機率 以1扣掉 因此為一定贏的機率




import java.util.*;

public class UVA10056 {

 public static void main(String[] args) {

  Scanner sc = new Scanner(System.in);

  int count = sc.nextInt();

  for (int i = 0; i < count; i++) {

   int N = sc.nextInt();

   double P = sc.nextDouble();

   int I = sc.nextInt();

   System.out.printf("%.4f", P == 0 ? P : P * Math.pow(1 - P, I - 1)
     / (1 - Math.pow(1 - P, N)));

   System.out.println();
  }

  sc.close();
 }

}