const double EPS = 1e-4; const int MAXN = 200; double c[MAXN], t[MAXN], r[MAXN]; int n, q, kase = 1; double otp, inp; bool check(double time, double all) { double cost = 0; REP(i, n) cost += max(0.0, time * (c[i] / t[i]) - r[i]); return cost <= all; } int main() { // freopen("in.txt", "r", stdin); while (~RII(n, q) && n) { otp = 0; printf("Case %d:\n", kase++); scanf("%lf", &inp); REP(i, n) { scanf("%lf%lf%lf", &c[i], &t[i], &r[i]); otp += c[i] / t[i]; } printf("%.0f\n", ceil(otp / inp)); REP(i, q) { int t; RI(t); double l = 0, r = 100001; while (l + EPS <= r) { double m = (l + r) / 2; if (check(m, t * inp * m)) l = m; else r = m; } if (l > 100000) puts("-1.000"); else printf("%.3f\n", l); } } return 0; }
Laptop Chargers,布布扣,bubuko.com
原文:http://blog.csdn.net/wty__/article/details/25804609