hdu 5105 Math Problem(数学)
pid=5105" target="_blank" style="">题目链接:hdu 5105 Math Problem
题目大意:给定a。b,c,d。l,r。表示有一个函数f(x)=|a∗x3+b∗x2+c∗x+d|(L≤x≤R),求函数最大值。
解题思路:考虑极点就可以,将函数求导后得到f′(x)=0的x,即为极值点。在极值点处函数的单调性会发生变化,所以最大值一定就在区间边界和极值点上。注意a=0。b=0的情况,以及极值点不在区间上。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps = 1e-9;
double A, B, C, D, L, R;
double function(double x) {
if (x >= L && x <= R) {
double y = A * x * x * x + B * x * x + C * x + D;
return fabs(y);
}
return -1;
}
double solve (double a, double b, double c) {
if (fabs(a) < eps) {
if (fabs(b) < eps)
return -1;
else
return function(- c / b);
}
double dta = b * b - 4 * a * c;
if (dta > 0) {
dta = sqrt(dta);
return max(function( (-b + dta) / 2 / a ), function( (-b - dta) / 2 / a) );
}
return -1;
}
int main () {
while (~scanf("%lf%lf%lf%lf%lf%lf", &A, &B, &C, &D, &L, &R)) {
double ans = max(function(L), function(R));
ans = max(ans, solve(3*A, 2*B, C));
while (ans < 0);
printf("%.2lf\n", ans);
}
return 0;
}
hdu 5105 Math Problem(数学)的更多相关文章
- HDU 5105 Math Problem --数学,求导
官方题解: f(x)=|a∗x3+b∗x2+c∗x+d|, 求最大值.令g(x)=a∗x3+b∗x2+c∗x+d,f(x)的最大值即为g(x)的正最大值,或者是负最小值.a!=0时, g′(x)=3∗ ...
- HDU 5105 Math Problem
让求 f(x)=|a∗x3+b∗x2+c∗x+d|(L≤x≤R)的最大值 这个题目讨论a和b的值,如果a==0的话,那么这个方程就变成了一个一元二次方程,直接找端点和对称轴(如果对称轴在给定的区间内 ...
- hdu 6182A Math Problem(快速幂)
You are given a positive integer n, please count how many positive integers k satisfy kk≤nkk≤n. Inp ...
- hdu5974 A Simple Math Problem(数学)
题目链接 大意:给你两个数X,YX,YX,Y,让你找两个数a,ba,ba,b,满足a+b=X,lcm(a,b)=Ya+b=X,lcm(a,b)=Ya+b=X,lcm(a,b)=Y. 思路:枚举gcd( ...
- HDU 5858 Hard problem (数学推导)
Hard problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5858 Description cjj is fun with ...
- HDU 5055 Bob and math problem(结构体)
主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5055 Problem Description Recently, Bob has been think ...
- [HDU - 5170GTY's math problem 数的精度类
题目链接:HDU - 5170GTY's math problem 题目描述 Description GTY is a GodBull who will get an Au in NOI . To h ...
- HDU 1757 A Simple Math Problem 【矩阵经典7 构造矩阵递推式】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1757 A Simple Math Problem Time Limit: 3000/1000 MS (J ...
- hdu 1757 A Simple Math Problem (乘法矩阵)
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
随机推荐
- 请求参数中的"+"号为什么会丢失,如何保证参数完整
最近在开发中碰见一个问题,后端代码调用接口,在请求端参数没有任何问题,但是当接口接收到参数时,其中的加号全部变为了空格. 在查阅资料后发现是URLDecoder方法的问题,以下是URLDecoder的 ...
- mysql绿色版配置
MySQL 绿色版安装配置教程 一.下载,这里使用绿色免安装版 1.网上搜索mysql绿色免安装版下载即可.提供官网地址 http://dev.mysql.com/downloads/mysql--- ...
- eclispe启动进入子项目的解决
问题描述: In Package Explorer I right-clicked on project and selected "Open in New Window". Ne ...
- Cocos2d-Lua 做一个活动转盘
这类活动你肯定见过 关于转盘类型的活动我相信大家多多少少都接触到了,很多的抽奖界面都是这类型的,今天这篇小文章就简单的总结一下我们游戏中需要实现这样一个效果的时候我们该怎样去做,其实只要是Cocos类 ...
- 【C++】const 常引用的用法
用法: const int & a; 定义了一个整型常引用变量a. 特点: 1.不能够通过常引用变量来修改其值,如: const int & a = 10; a = 12;//编译报错 ...
- python sql语句封装连接mysql
进行了代码优化,欢迎评审 #!/usr/bin/python # -*- coding:utf-8 -*- import logging logging.basicConfig(level=loggi ...
- 浅谈Java中final,finalized,finally
final: final可以让你控制你的成员.方法或者是一个类是否可被覆写或继承等功能,这些特点使final在Java中拥有了一个不可或缺的地位,也是学习Java时必须要知道和掌握的关键字之一. fi ...
- [BZOJ2655]calc(拉格朗日插值法+DP)
2655: calc Time Limit: 30 Sec Memory Limit: 512 MBSubmit: 428 Solved: 246[Submit][Status][Discuss] ...
- 【kd-tree】CDOJ - 1170 - 红与蓝
kd-tree模板题,对红点建立kd-tree,用每个蓝点查询,更新最小值即可. #include<cstdio> #include<cmath> #include<al ...
- [Interview] 程序员如何制作一份漂亮的面试简历
简历模板 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; ...