175D - Plane of Tanks Duel - CodeForces Solution


brute force dp math probabilities *2400

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
using ld = double;
int hp[2], d[2], p[2], l[2], r[2], t[2];
ld dp[2][202], ans[2], co[2];

void calc(int k) {
    t[k] += d[k];
    for (int i=1; i<=hp[k^1]; i++) if (dp[k^1][i] > 1e-9) {
        for (int j=l[k]; j<=r[k]; j++) dp[k^1][max(0, i-j)] += co[k] * dp[k^1][i];
        dp[k^1][i] *= p[k]*.01;
    }
    ans[k] += (1-dp[k][0]) * dp[k^1][0];
    if (!k) dp[1][0] = 0;
}

int main() {
    for (int i=0; i<2; i++) {
        cin >> hp[i] >> d[i] >> l[i] >> r[i] >> p[i];
        if (p[i] == 100) {
            printf("%d\n", i);
            return 0;
        }
        co[i] = 1.0/(r[i]+1-l[i])*(1 - .01*p[i]);
        dp[i][hp[i]] = 1;
    }
    for (int i=0; i<9999; i++) calc(t[0] > t[1]);
    printf("%.9lf\n", ans[0]);
}


Comments

Submit
0 Comments
More Questions

25B - Phone numbers
1633C - Kill the Monster
1611A - Make Even
1030B - Vasya and Cornfield
1631A - Min Max Swap
1296B - Food Buying
133A - HQ9+
1650D - Twist the Permutation
1209A - Paint the Numbers
1234A - Equalize Prices Again
1613A - Long Comparison
1624B - Make AP
660B - Seating On Bus
405A - Gravity Flip
499B - Lecture
709A - Juicer
1358C - Celex Update
1466B - Last minute enhancements
450B - Jzzhu and Sequences
1582C - Grandma Capa Knits a Scarf
492A - Vanya and Cubes
217A - Ice Skating
270A - Fancy Fence
181A - Series of Crimes
1638A - Reverse
1654C - Alice and the Cake
369A - Valera and Plates
1626A - Equidistant Letters
977D - Divide by three multiply by two
1654B - Prefix Removals