Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package dungeonsanddragons;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.math.RoundingMode;
- import java.text.DecimalFormat;
- import java.util.Arrays;
- import java.util.StringTokenizer;
- /**
- *
- * @author Aaron Zhou
- */
- public class Dungeonsanddragons {
- /**
- * @param args the command line arguments
- */
- static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- static StringTokenizer st;
- static double[][] memo;
- public static double calculate(int hp, int atk, int def, double ac, int hpp, int atkp, int defp, double acp, int counter) {
- double out = 0;
- if (hp <= 0) {
- return 1;
- } else if (hpp <= 0) {
- return 0;
- }
- if (counter == 15) {
- return 0.5;
- }
- int trueatk = 0;
- int trueatke = 0;
- for (int i = 1; i < 9; i++) {
- trueatk = atkp - def + i;
- if (trueatk < 0) {
- trueatk = 0;
- }
- for (int j = 1; j < 9; j++) {
- trueatke = atk - defp + j;
- if (trueatke < 0) {
- trueatke = 0;
- }
- if (memo[hp][hpp] == -1.0) {
- out += ((((acp / 20.0) * ((20.0 - ac) / 20.0)) * calculate((hp - trueatk), atk, def, ac, hpp, atkp, defp, acp, counter + 1))
- + ((((20.0 - acp) / 20.0) * ((20.0 - ac) / 20.0)) * calculate(hp, atk, def, ac, hpp, atkp, defp, acp, counter + 1))
- + ((((20.0 - acp) / 20.0) * (ac / 20.0)) * calculate(hp, atk, def, ac, hpp - trueatke, atkp, defp, acp, counter + 1))
- + (((acp / 20.0) * (ac / 20.0)) * calculate(hp - trueatk, atk, def, ac, hpp - trueatke, atkp, defp, acp, counter + 1)));
- memo[hp][hpp] = out;
- } else {
- out = memo[hp][hpp];
- }
- }
- }
- return out;
- }
- public static void main(String[] args) throws IOException {
- int hpplayer = readInt();
- int atkplayer = readInt();
- int defplayer = readInt();
- int acplayer = readInt();
- int numenemies = readInt();
- for (int i = 0; i < numenemies; i++) {
- int hp = readInt();
- int atk = readInt();
- int def = readInt();
- double ac = readDouble();
- memo = new double[(int) hp + 1][(int) hpplayer + 1];
- for (int k = 0; k < hp + 1; k++) {
- for (int j = 0; j < hpplayer + 1; j++) {
- memo[hp][hpplayer] = -1;
- }
- }
- double chances = calculate(hp, atk, def, ac, hpplayer, atkplayer, defplayer, acplayer, 0);
- if (chances == 0) {
- System.out.println("Get outta there!");
- } else {
- DecimalFormat df = new DecimalFormat("0.00000");
- df.setRoundingMode(RoundingMode.CEILING);
- System.out.println(df.format(chances));
- }
- }
- }
- static String next() throws IOException {
- while (st == null || !st.hasMoreTokens()) {
- st = new StringTokenizer(br.readLine().trim());
- }
- return st.nextToken();
- }
- static double readLong() throws IOException {
- return Long.parseLong(next());
- }
- static int readInt() throws IOException {
- return Integer.parseInt(next());
- }
- static double readDouble() throws IOException {
- return Double.parseDouble(next());
- }
- static char readCharacter() throws IOException {
- return next().charAt(0);
- }
- static String readLine() throws IOException {
- return br.readLine().trim();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement