HDU-4525 威威猫系列故事——吃鸡腿

时间:2023-05-12 15:22:32

题意:给定一个正整数A,告知等比数列的公比为q,为这个序列能否超过一个特定的数K。

解法:该题需要考虑公比的取值,当q=1,q=-1,q=0的特殊性,由于等比数列的增长速度非常快,所以可以for循环扫描过去。

#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std; typedef long long LL;
const int N = ;
int n;
int seq[N];
int k1, k2;
LL K; int main() {
int T, ca = ;
scanf("%d", &T);
while (T--) {
LL sum = ;
int c;
scanf("%d %d %d %I64d", &n, &k1, &k2, &K);
for (int i = ; i < n; ++i) {
scanf("%d", &c);
sum += c;
}
printf("Case #%d: ", ++ca);
if (sum > K) {
puts("");
continue;
}
int k3 = k1 + k2;
if (k3 >= ) {
if (k3 <= ) {
puts("inf");
} else {
int d = ;
while ((long double)1.0*sum <= (long double)1.0*K/k3) ++d, sum*=k3;
printf("%d\n", d);
}
} else {
if (k3 == -) {
puts("inf");
} else {
k3 *= -;
int d = ;
while ((long double)1.0*sum <= (long double)1.0*K/k3) ++d, sum*=k3;
if (d & ) printf("%d\n", d+);
else printf("%d\n", d);
}
}
}
return ;
}