CodeForces 175D Plane of Tanks: Duel (概率)

来源:互联网 发布:ubuntu安装VPN Client 编辑:程序博客网 时间:2024/06/05 17:50
#include <iostream>#include <cstdio>#include <vector>#include <cstring>#include <cmath>using namespace std;#define N 100020#define T 5030#define eps 1e-8int hp0, dt0, l0, r0;int hp1, dt1, l1, r1;double p0, p1;double f0[220], f1[220];bool att(double f[220], int l, int r, double p) {bool ret = 0;for(int i = 1; i <= 200; ++i) {if(f[i] < 1e-12) continue;ret = 1;for(int j = l; j <= r; ++j) {f[max(i - j, 0)] += f[i] * (1 - p) / (r - l + 1);}f[i] *= p;}return ret;}int main() {scanf("%d%d%d%d%lf", &hp0, &dt0, &l0, &r0, &p0);scanf("%d%d%d%d%lf", &hp1, &dt1, &l1, &r1, &p1);p0 /= 100, p1 /= 100;if(p0 > 0.999) {puts("0");return 0;}if(p1 > 0.999) {puts("1");return 0;}f0[hp0] = 1;f1[hp1] = 1;int t0 = 0, t1 = 0;double ans = 0;while(1) {if(t0 <= t1) {t0 += dt0;f1[0] = 0;att(f1, l0, r0, p0);ans += (1 - f0[0]) * f1[0];}else {t1 += dt1;if(!att(f0, l1, r1, p1)) break;}}printf("%.12lf\n", ans);return 0;}

0 0
原创粉丝点击