Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package dungeonsanddragons;
  7.  
  8. import java.io.BufferedReader;
  9. import java.io.IOException;
  10. import java.io.InputStreamReader;
  11. import java.math.RoundingMode;
  12. import java.text.DecimalFormat;
  13. import java.util.Arrays;
  14. import java.util.StringTokenizer;
  15.  
  16. /**
  17. *
  18. * @author Aaron Zhou
  19. */
  20. public class Dungeonsanddragons {
  21.  
  22. /**
  23. * @param args the command line arguments
  24. */
  25. static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  26. static StringTokenizer st;
  27. static double[][] memo;
  28.  
  29. public static double calculate(int hp, int atk, int def, double ac, int hpp, int atkp, int defp, double acp, int counter) {
  30. double out = 0;
  31. if (hp <= 0) {
  32. return 1;
  33.  
  34. } else if (hpp <= 0) {
  35. return 0;
  36.  
  37. }
  38.  
  39. if (counter == 15) {
  40. return 0.5;
  41.  
  42. }
  43.  
  44. int trueatk = 0;
  45. int trueatke = 0;
  46.  
  47. trueatk = atkp - def;
  48. if (trueatk < 0) {
  49. trueatk = 0;
  50. }
  51. trueatke = atk - defp;
  52. if (trueatke < 0) {
  53. trueatke = 0;
  54. }
  55. if (memo[hp][hpp] == -1.0) {
  56. out += ((((acp / 20.0) * ((20.0 - ac) / 20.0)) * calculate((hp - trueatk), atk, def, ac, hpp, atkp, defp, acp, counter + 1))
  57. + ((((20.0 - acp) / 20.0) * ((20.0 - ac) / 20.0)) * calculate(hp, atk, def, ac, hpp, atkp, defp, acp, counter + 1))
  58. + ((((20.0 - acp) / 20.0) * (ac / 20.0)) * calculate(hp, atk, def, ac, hpp - trueatke, atkp, defp, acp, counter + 1))
  59. + (((acp / 20.0) * (ac / 20.0)) * calculate(hp - trueatk, atk, def, ac, hpp - trueatke, atkp, defp, acp, counter + 1)));
  60. memo[hp][hpp] = out;
  61. } else {
  62. out = memo[hp][hpp];
  63. }
  64.  
  65. return out;
  66. }
  67.  
  68. public static void main(String[] args) throws IOException {
  69.  
  70. int hpplayer = readInt();
  71. int atkplayer = readInt();
  72. int defplayer = readInt();
  73. int acplayer = readInt();
  74. int numenemies = readInt();
  75. for (int i = 0; i < numenemies; i++) {
  76. int hp = readInt();
  77. int atk = readInt();
  78. int def = readInt();
  79. double ac = readDouble();
  80. memo = new double[(int) hp + 1][(int) hpplayer + 1];
  81. for (int k = 0; k < hp + 1; k++) {
  82. for (int j = 0; j < hpplayer + 1; j++) {
  83. memo[hp][hpplayer] = -1;
  84. }
  85. }
  86. double chances = calculate(hp, atk, def, ac, hpplayer, atkplayer, defplayer, acplayer, 0);
  87. if (chances == 0) {
  88. System.out.println("Get outta there!");
  89. } else {
  90. DecimalFormat df = new DecimalFormat("0.00000");
  91. df.setRoundingMode(RoundingMode.CEILING);
  92.  
  93. System.out.println(df.format(chances));
  94. }
  95. }
  96.  
  97. }
  98.  
  99. static String next() throws IOException {
  100. while (st == null || !st.hasMoreTokens()) {
  101. st = new StringTokenizer(br.readLine().trim());
  102. }
  103. return st.nextToken();
  104. }
  105.  
  106. static double readLong() throws IOException {
  107. return Long.parseLong(next());
  108. }
  109.  
  110. static int readInt() throws IOException {
  111. return Integer.parseInt(next());
  112. }
  113.  
  114. static double readDouble() throws IOException {
  115. return Double.parseDouble(next());
  116. }
  117.  
  118. static char readCharacter() throws IOException {
  119. return next().charAt(0);
  120. }
  121.  
  122. static String readLine() throws IOException {
  123. return br.readLine().trim();
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement