题目链接:hdu 4823 Energy Conversion
题目大意:中文题,不解释。
解题思路:首先判断一下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
时间: 2024-10-25 15:09:02