标签:style class c code tar http
题目大意:中文题,不解释。
解题思路:首先判断一下m是否已经大于n了,如果大于那么就是0,假设中间变换的各个值为ai,那么bi=ai+c,bi数组为等比数组(可推),所以就有了cnt=log((n+c)a)log(double(k)),结果为浮点数,需要向上取整。
#include <cstdio>
#include <cstring>
#include <cmath>
int main () {
int cas;
double n, m, v, k;
scanf("%d", &cas);
while (cas--) {
scanf("%lf%lf%lf%lf", &n, &m, &v, &k);
if (m >= n) {
printf("0\n");
continue;
}
double tmp = (m-v)*k;
if (tmp <= m) {
printf("-1\n");
} else {
double c = -(v * k) / (k - 1);
double a = m + c;
double cnt = log((n+c) / a) / log(double(k));
printf("%lld\n", (long long)ceil(cnt));
}
}
return 0;
}
hdu 4823 Energy Conversion(数学),布布扣,bubuko.com
hdu 4823 Energy Conversion(数学)
标签:style class c code tar http
原文地址:http://blog.csdn.net/keshuai19940722/article/details/26516291