Laptop Chargers

时间:2014-05-15 02:33:39   收藏:0   阅读:239

题目链接

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

评论(0)
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!