Main.java 835 B

123456789101112131415161718192021222324252627
  1. import java.util.Scanner;
  2. public class Main {
  3. public static void main(String[] args) {
  4. Scanner scanner = new Scanner(System.in);
  5. int P = scanner.nextInt();
  6. int Q = scanner.nextInt();
  7. int N = scanner.nextInt();
  8. double res = 0.0;
  9. int p1 = 0;
  10. // E(X + Y) = E(X) + E(Y)
  11. // Getting the ith item is independent!
  12. for (int i = 0; i < N; i++) {
  13. if (8 <= i) p1 = 0;
  14. else p1 = P / (int) Math.pow(2, i);
  15. double p2 = 1.0;
  16. for (int j = 1; j <= 100; j++) {
  17. res += p1 / 100.0 * p2 * j;
  18. if (p1 == 100) break;
  19. p2 *= 1.0 - p1 / 100.0;
  20. p1 = p1 + Q > 100 ? 100 : p1 + Q;
  21. }
  22. }
  23. System.out.printf("%.2f", res);
  24. scanner.close();
  25. }
  26. }