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 ...
随机推荐
- import详解
试想一下 在工作中今年在一个项目中可能会导入某一个目录下的模块文件,那这个时候怎么样才能让Python解释器能够找到该模块进行调用呢? - 将这个模块拷贝一份到当前使用目录下. 这种方式让模块太冗余 ...
- 动态加载ajax 腾讯视频评论
import urllib import urllib2 import os import requests import re import json sns_url = 'http://sns.v ...
- 对数据访问层的重构(及重构中Perl的应用)
以前上学的时候,听到“一个学生在毕业后刚刚开始编程的头几年中,写出的代码多半是垃圾”这样的说法,均不屑一顾.现在工作一年多了,越发感觉自己代码中疏漏处甚多,故近来常做亡羊补牢的重构之举.拿自己4个月前 ...
- sonarQube6.1 升级至6.2
在使用sonarQube6.1一段时间后,今天才发现sonarQube6.2已经更新,为了尝鲜,我决定在本机先尝试一下,如何升级至6.2 在这里,根据站点提示的升级步骤 1.下载新版本sonarQub ...
- HDU 1233.还是畅通工程-最小生成树(Prime)
还是畅通工程 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- 链式前向星写法下的DFS和BFS
Input 5 7 1 2 2 3 3 4 1 3 4 1 1 5 4 5 output 1 5 3 4 2 #include<bits/stdc++.h> using namespace ...
- 2017中国大学生程序设计竞赛 - 女生专场B【DP】
B HDU - 6024 [题意]:n个教室,选一些教室建造糖果商店. 每个教室,有一个坐标xi和在这个教室建造糖果商店的花费ci. 对于每一个教室,如果这个教室建造糖果商店,花费就是ci,否则就是与 ...
- python formatters 与字符串 小结 (python 2)
最近学习python 2 ,觉得有必要小结一下关于字符串处理中的formatters, 转载请声明本文的引用出处:仰望大牛的小清新 0.%进行变量取值使用的时机 在python中,如果我们只是需要在字 ...
- 36、Django实战第36天:首页功能开发
1.编辑users.views.py ... class IndexView(View): """ 首页 """ def get(self, ...
- [PKUSC2018]神仙的游戏(FFT)
给定一个01?串,对所有len询问是否存在一种填法使存在长度为len的border. 首先有个套路的性质:对于一个长度为len的border,这个字符串一定有长度为n-len的循环节(最后可以不完整) ...