QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#231690 | #6423. Fireworks | veg# | WA | 1ms | 4024kb | C++14 | 1.3kb | 2023-10-29 15:37:21 | 2023-10-29 15:37:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
double n, m, p, tmp, ans;
double calc(int k) {
return (k * n + m) / (1 - pow(1 - p, k));
}
double get(double mid) {
return pow(1 - p, mid) * (-tmp * n * mid - m * tmp + n);
}
void div1(double l, double r) {
while (r - l > 1e-3) {
double mid = (l + r) / 2;
if (get(mid) < n) l = mid;
else r = mid;
}
int k1 = floor(l), k2 = ceil(l);
ans = min(ans, calc(k1));
ans = min(ans, calc(k2));
}
void div2(double l, double r) {
while (r - l > 1e-3) {
double mid = (l + r) / 2;
if (get(mid) < n) r = mid;
else l = mid;
}
int k1 = floor(l), k2 = ceil(l);
ans = min(ans, calc(k1));
ans = min(ans, calc(k2));
}
int main() {
int T;
cin >> T;
while (T--) {
scanf("%lf%lf%lf", &n, &m, &p);
p /= 10000;
tmp = log(1 - p);
double l = 0, r = 1e4;
while (r - l > 1e-3) {
double lmid = l + (r - l) / 3;
double rmid = r - (r - l) / 3;
double lv = get(lmid);
double rv = get(rmid);
if (fabs(lv - rv) < 1e-4) {
l = lmid;
r = rmid;
} else if (lv < rv)
l = lmid;
else
r = rmid;
}
// cerr << l << endl;
ans = calc(1);
if (get(0) < n && n < get(l)) div1(0, l);
if (get(1e9) < n && n < get(l)) div2(l, 1e9);
// for (int i = 1; i <= 100; ++i) cerr << calc(i) << endl;
printf("%.6lf\n", ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4024kb
input:
3 1 1 5000 1 1 1 1 2 10000
output:
4.000000 10141.585289 3.000000
result:
ok 3 numbers
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3888kb
input:
20 10 27 2855 79 59 6888 65 72 7725 78 50 2888 31 21 5759 41 58 6619 47 27 3881 35 55 5095 77 7 6028 17 89 1792 84 60 8604 58 44 4923 88 27 3824 54 63 1482 19 42 5366 93 76 97 100 99 8660 96 36 4343 90 56 9515 24 44 9922
output:
129.597198 200.348432 177.346278 443.213296 90.293454 149.569421 190.672507 176.643768 139.349701 591.517857 167.364017 207.190737 300.732218 789.473684 113.678718 17422.680412 229.792148 303.937370 153.441934 68.534570
result:
wrong answer 1st numbers differ - expected: '89.72981', found: '129.59720', error = '0.44430'