首页 > 试题广场 >

小红的函数最大值

[编程题]小红的函数最大值
  • 热度指数:1151 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
小红希望你求出函数 f(x)=log_a x-bx 在定义域上的最大值。你能帮帮她吗?

输入描述:
两个正整数a,b,用空格隔开
2\leq a \leq 1000
1\leq b \leq 1000


输出描述:
该函数在定义域上的最大值。你只需要保证和标准答案的相对误差不超过10^{-7}即可通过本题。
示例1

输入

2 1

输出

-0.9139286679
头像 牛客77911743号
发表于 2025-04-27 10:51:47
import sys import math # 定义域为x>0, 先增大后减小, f的导数为0时为最大值 for line in sys.stdin: a,b = map(int,line.strip().split()) x = 1 / (b*math.log(a)) 展开全文
头像 牛牛无敌a
发表于 2025-04-01 21:31:08
#include <cmath> #include <iomanip> #include <iostream> using namespace std; // 函数用于计算 log_a(x) double log_base(double x, double ba 展开全文
头像 我很强我知道
发表于 2025-06-05 16:37:09
#include <iostream> #include<cmath> #include<iomanip> using namespace std; int main() { int a, b; while (cin >> a > 展开全文
头像 当时月
发表于 2025-04-16 13:06:45
from math import log def com_max(a, b): x = 1 / (b * log(a)) ans = log(x)/log(a) - b*x return ans def main(): nums = [int(i) for i i 展开全文
头像 牛客967526391号
发表于 2025-04-05 13:52:09
#include <stdio.h> #include <math.h> int main() { double a,b; scanf("%lf %lf",&a,&b); // 手算出最大取值点x // 计算 展开全文
头像 爱吃肉的太平湖水怪在刷代码
发表于 2025-04-03 20:07:31
#include <iostream> #include <cmath> #include <cstdio> using namespace std; int main() { int a, b; cin >> a >> b; 展开全文
头像 Qadccccc
发表于 2025-05-08 14:35:00
import sys import math for line in sys.stdin: nums=list(map(int,line.strip().split())) #print(int(a[0]) + int(a[1])) a= nums[0] b= num 展开全文
头像 Lavada
发表于 2025-05-22 13:45:45
#include <iostream> #include <cmath> #include <cstdio> using namespace std; int main() { //f(x) 是先增后减函数 int a,b; cin> 展开全文