Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 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. for (int i = 1; i < 9; i++) {
  47. trueatk = atkp - def + i;
  48. if (trueatk < 0) {
  49. trueatk = 0;
  50. }
  51. for (int j = 1; j < 9; j++) {
  52. trueatke = atk - defp + j;
  53. if (trueatke < 0) {
  54. trueatke = 0;
  55. }
  56. if (memo[hp][hpp] == -1.0) {
  57. out += ((((acp / 20.0) * ((20.0 - ac) / 20.0)) * calculate((hp - trueatk), atk, def, ac, hpp, atkp, defp, acp, counter + 1))
  58. + ((((20.0 - acp) / 20.0) * ((20.0 - ac) / 20.0)) * calculate(hp, atk, def, ac, hpp, atkp, defp, acp, counter + 1))
  59. + ((((20.0 - acp) / 20.0) * (ac / 20.0)) * calculate(hp, atk, def, ac, hpp - trueatke, atkp, defp, acp, counter + 1))
  60. + (((acp / 20.0) * (ac / 20.0)) * calculate(hp - trueatk, atk, def, ac, hpp - trueatke, atkp, defp, acp, counter + 1)));
  61. memo[hp][hpp] = out;
  62. } else {
  63. out = memo[hp][hpp];
  64. }
  65. }
  66. }
  67. return out;
  68. }
  69.  
  70. public static void main(String[] args) throws IOException {
  71.  
  72. int hpplayer = readInt();
  73. int atkplayer = readInt();
  74. int defplayer = readInt();
  75. int acplayer = readInt();
  76. int numenemies = readInt();
  77. for (int i = 0; i < numenemies; i++) {
  78. int hp = readInt();
  79. int atk = readInt();
  80. int def = readInt();
  81. double ac = readDouble();
  82. memo = new double[(int) hp + 1][(int) hpplayer + 1];
  83. for (int k = 0; k < hp + 1; k++) {
  84. for (int j = 0; j < hpplayer + 1; j++) {
  85. memo[hp][hpplayer] = -1;
  86. }
  87. }
  88. double chances = calculate(hp, atk, def, ac, hpplayer, atkplayer, defplayer, acplayer, 0);
  89. if (chances == 0) {
  90. System.out.println("Get outta there!");
  91. } else {
  92. DecimalFormat df = new DecimalFormat("0.00000");
  93. df.setRoundingMode(RoundingMode.CEILING);
  94.  
  95. System.out.println(df.format(chances));
  96. }
  97. }
  98.  
  99. }
  100.  
  101. static String next() throws IOException {
  102. while (st == null || !st.hasMoreTokens()) {
  103. st = new StringTokenizer(br.readLine().trim());
  104. }
  105. return st.nextToken();
  106. }
  107.  
  108. static double readLong() throws IOException {
  109. return Long.parseLong(next());
  110. }
  111.  
  112. static int readInt() throws IOException {
  113. return Integer.parseInt(next());
  114. }
  115.  
  116. static double readDouble() throws IOException {
  117. return Double.parseDouble(next());
  118. }
  119.  
  120. static char readCharacter() throws IOException {
  121. return next().charAt(0);
  122. }
  123.  
  124. static String readLine() throws IOException {
  125. return br.readLine().trim();
  126. }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement