CF1543C Need for Pink Slips
CF1543C Need for Pink Slips
我没想到的是,
这个题的正解就是暴力...
没什么好说的,
除了题目难读懂之外,
别的都毫无难度.
对了,
注意精度
每逢浮点数都要注意精度.
code:
#include <cstdio>
#include <iostream>
using namespace std;
const double eps = 1e-6;
int T;
double v, ans;
void dfs(double a, double b, double c, double d, double e){
ans += c * d * e;
if (a > eps){
if (b > eps){
if (a > v) dfs(a - v, b + v / 2, c + v / 2, d * a, e + 1);
else dfs(0, b + a / 2, c + a / 2, d * a, e + 1);
if (b > v) dfs(a + v / 2, b - v, c + v / 2, d * b, e + 1);
else dfs(a + b / 2, 0, c + b / 2, d * b, e + 1);
}
else {
if (a > v) dfs(a - v, 0, c + v, d * a, e + 1);
else dfs(0, 0, 1, d * a, e + 1);
}
}
else if (b > eps){
if (b > v) dfs(0, b - v, c + v, d * b, e + 1);
else dfs(0, 0, 1, d * b, e + 1);
}
}
int main(){
double c, m, p;
cin >> T;
while (T--){
ans = 0;
cin >> c >> m >> p >> v;
dfs(c, m, p, 1, 1);
printf("%.12lf\n", ans);
}
return 0;
}
看不见我看不见我看不见我