BestCoder Round #18(hdu5105)Math Problem(高中数学)
最大值无非就是在两个端点或极值点处取得。
我注意讨论了a=0和b=0,却忽略了极值点可能不在L到R的范围内这一问题。被Hack了。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<cctype>
#include<sstream>
using namespace std;
#define pii pair<int,int>
#define LL long long int
const int eps=1e-;
const int INF=;
const int maxn=+;
double a,b,c,d,L,R,ans;
double f(double x)
{
return fabs(a*x*x*x+b*x*x+c*x+d);
}
int main()
{
//freopen("in10.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&L,&R)==)
{
if(a!=)
{
if(a<)
{
a=-a;
b=-b;
c=-c;
d=-d;
}
double pan=b*b-*a*c;
if(pan<=)
{
printf("%.2f\n",max(f(L),f(R)));
}
else
{
double x1=(-sqrt(pan)-b)/(*a);
double x2=(sqrt(pan)-b)/(*a);
if(x1>=L&&x1<=R&&x2>=L&&x2<=R)
printf("%.2f\n",max(max(f(L),f(R)),max(f(x1),f(x2))));
else if(x1>=L&&x1<=R)
printf("%.2f\n",max(f(L),max(f(R),f(x1))));
else if(x2>=L&&x2<=R)
printf("%.2f\n",max(f(L),max(f(R),f(x2))));
else printf("%.2f\n",max(f(L),f(R)));
}
}
else
{
if(b==) printf("%.2f\n",max(f(L),f(R)));
else
{
double z=(-c)/(*b);
if(z<=R&&z>=L)
printf("%.2f\n",max(f(L),max(f(R),f(z))));
else printf("%.2f\n",max(f(L),f(R)));
}
}
}
//fclose(stdin);
//fclose(stdout);
return ;
}
BestCoder Round #18(hdu5105)Math Problem(高中数学)的更多相关文章
- Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) A. Math Problem 水题
A. Math Problem Your math teacher gave you the following problem: There are n segments on the x-axis ...
- 2016ICPC-大连 A Simple Math Problem (数学)
Given two positive integers a and b,find suitable X and Y to meet the conditions: X+Y=a Least Common ...
- Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) A Math Problem
//只要从所有区间右端点的最小值覆盖到所有区间左端点的最大值即可 #include<iostream> using namespace std ; int x,y; int n; int ...
- Math Problem(数学)
链接:https://ac.nowcoder.com/acm/contest/893/C来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K ...
- BestCoder Round #29——A--GTY's math problem(快速幂(对数法))、B--GTY's birthday gift(矩阵快速幂)
GTY's math problem Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- BestCoder Round #70 Jam's math problem(hdu 5615)
Problem Description Jam has a math problem. He just learned factorization. He is trying to factorize ...
- hdu 5105 Math Problem(数学)
pid=5105" target="_blank" style="">题目链接:hdu 5105 Math Problem 题目大意:给定a.b ...
- hdu 5667 BestCoder Round #80 矩阵快速幂
Sequence Accepts: 59 Submissions: 650 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...
- hdu----(5055)Bob and math problem(贪心)
Bob and math problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
随机推荐
- 1.2 使用电脑测试MC20模块的GPS功能测试
需要准备的硬件 MC20开发板 1个 https://item.taobao.com/item.htm?id=562661881042 GSM/GPRS天线 1根 https://item.taoba ...
- 基于CentOS的SSHD服务的Docker镜像
原文地址 1.Dockerfile文件 FROM registry.aliyuncs.com/acs-sample/centos:6 MAINTAINER xuqh "xqh_163@163 ...
- Nexus Repository Manager 使用笔记
在使用maven是,因内外网限制往往需要配置自由的maven库,小编看见网上教程数不胜数,遍主动试试 以下是下载地址 : http://www.sonatype.com/download-oss-so ...
- 我的npm笔记
本文记录一些npm的使用技巧,主要包括自己常用的命令,做个备忘. NPM 是什么? NPM是NodeJS的包管理工具,现在已经进一步发展,致力于为很多其他平台提供包管理工具,其核心思想就是让包的安装更 ...
- Loadrunder之脚本篇——参数化方法
导语 参数化旨在模拟多数据来进行测试,所以再选择参数化你明确你参数化的内容! 方法一 1.确定需要参数化的内容 2.选中需要参数化的内容 3.右键选中的内容->Replace with a Pa ...
- Linux进程优先级查看及修改
进程cpu资源分配就是指进程的优先权(priority).优先权高的进程有优先执行权利.配置进程优先权对多任务环境的Linux很有用,可以改善系统性能.还可以把进程运行到指定的CPU上,这样一来,把不 ...
- qt的登录设置(转)
1.下面添加代码来实现使用用户名和密码登录,这里只是简单将用户名和密码设置为了固定的字符串,如果以后学习了数据库,还可以通过读取数据库来获取用户名和密码.到logindialog.cpp文件中将登录按 ...
- 标准输出:1>,2>,1>&2,2>&1
在 shell 程式中,最常使用的 FD (file descriptor) 大概有三个, 分别是: 0 是一个文件描述符,表示标准输入(stdin)1 是一个文件描述符,表示标准输出(stdout) ...
- python进阶03
进程线程不管哪门语言都是一块可以被重视的方向,下面一起学习学习python中的进程,线程 1.进程线程区别 通俗解释:一个程序QQ的运行就是一个进程运行:QQ中打开多个页面互不影响可以同时操作的每个页 ...
- YARN中的失败分析
YARN中的失败分析 对于在YARN中运行的MapReduce程序,需要考虑以下几种实体的失败任务.application master.节点管理器.资源管理器 1. 任务运行失败 任务运行失败类似于 ...