题目链接:

huangjing

题目:

思路:

给出的是一个方程,首先讨论最高项系数。

1:a==0&& b==0  那么函数就是线性的。直接比較端点就可以。

2   a==0&&b!=0  那么函数就是二次函数。直接算出特征值,然后比較端点值就可以。。

3  a!=0  又有几种情况,那么当特征根  b*b-4*a*c<0 时  说明愿函数是单调,直接比較端点值就可以。

当大于0的时候,直接求出两个根,然后和端点值比較就可以

ps:全部的特征根都要是有效的,即都要在[L,R]之间。

题目:

Math Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 943    Accepted Submission(s): 250

Problem Description
Here has an function:

  f(x)=|a∗x3+b∗x2+c∗x+d|(L≤x≤R)

Please figure out the maximum result of f(x).
 
Input
Multiple test cases(less than 100). For each test case, there will be only 1 line contains 6 numbers a, b, c, d, L and R. (−10≤a,b,c,d≤10,−100≤L≤R≤100)
 
Output
For each test case, print the answer that was rounded to 2 digits after decimal point in 1 line.
 
Sample Input
1.00 2.00 3.00 4.00 5.00 6.00
 
Sample Output
310.00
 
Source
 
Recommend
 

pid=5105" style="color:rgb(26,92,200); text-decoration:none">Statistic | Submit | 

problemid=5105" style="color:rgb(26,92,200); text-decoration:none">Discuss | Note


代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
#define eps 1e-9
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
priority_queue<int,vector<int>,greater<int> >Q; double a,b,c,d,l,r; double f(double x)
{
return fabs(a*x*x*x+b*x*x+c*x+d);
} int main()
{
double ans;
while(~scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&l,&r))
{
if(a==0&&b!=0)
{
double x=-c/(2*b);
ans=max(f(l),f(r));
if(x>=l&&x<=r)
ans=max(ans,f(x));
}
else if(a==0&&b==0)
ans=max(f(l),f(r));
else if(a!=0)
{
double xx=4*b*b-12*a*c;
if(xx<0)
ans=max(f(l),f(r));
else
{
double x1=(-2*b+sqrt(xx))/(6*a);
double x2=(-2*b-sqrt(xx))/(6*a);
ans=max(f(l),f(r));
if(x1>=l&&x1<=r)
ans=max(ans,f(x1));
if(x2>=l&&x2<=r)
ans=max(ans,f(x2));
}
}
printf("%.2lf\n",ans);
}
return 0;
}

hdu5105Math Problem(分类讨论)的更多相关文章

  1. D. Easy Problem dp(有衔接关系的dp(类似于分类讨论) )

    D. Easy Problem dp(有衔接关系的dp(类似于分类讨论) ) 题意 给出一个串 给出删除每一个字符的代价问使得串里面没有hard的子序列需要付出的最小代价(子序列不连续也行) 思路 要 ...

  2. Codeforces 1513F - Swapping Problem(分类讨论+乱搞)

    Codeforces 题目传送门 & 洛谷题目传送门 简单题,难度 *2500 的 D2F,就当调节一下一模炸裂了的自闭的心情,稍微写写吧. 首先我看到这题的第一反应是分类讨论+数据结构,即枚 ...

  3. cf 251 B Playing with Permutations 暴力 分类讨论

    题链;http://codeforces.com/problemset/problem/251/B B. Playing with Permutations time limit per test 2 ...

  4. CCCC L2-010. 排座位【并查集/分类讨论】

    L2-010. 排座位 时间限制 150 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 布置宴席最微妙的事情,就是给前来参宴的各位宾客安排座位. ...

  5. HDU 6627 equation (分类讨论)

    2019 杭电多校 5 1004 题目链接:HDU 6627 比赛链接:2019 Multi-University Training Contest 5 Problem Description You ...

  6. HDU 6665 Calabash and Landlord (分类讨论)

    2019 杭电多校 8 1009 题目链接:HDU 6665 比赛链接:2019 Multi-University Training Contest 8 Problem Description Cal ...

  7. Codeforces 460D Little Victor and Set --分类讨论+构造

    题意:从区间[L,R]中选取不多于k个数,使这些数异或和尽量小,输出最小异或和以及选取的那些数. 解法:分类讨论. 设选取k个数. 1. k=4的时候如果区间长度>=4且L是偶数,那么可以构造四 ...

  8. BZOJ-1067 降雨量 线段树+分类讨论

    这道B题,刚的不行,各种碎点及其容易忽略,受不鸟了直接 1067: [SCOI2007]降雨量 Time Limit: 1 Sec Memory Limit: 162 MB Submit: 2859 ...

  9. UVaLive 6862 Triples (数学+分类讨论)

    题意:给定一个n和m,问你x^j + y^j = z^j 的数量有多少个,其中0 <= x <= y <= z <= m, j = 2, 3, 4, ... n. 析:是一个数 ...

随机推荐

  1. android studio2.2 配置NDK

    1.配置环境: Android studio2.2 配置NDK NDK版本[android-ndk-r13b-windows-x86_64.zip] NDK下载网址:[https://dl.googl ...

  2. 监控Apache计数器

  3. LaTeX 插图片

    本系列文章由 @YhL_Leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50240371 这里列出3种LaTeX中 ...

  4. JQuery与CSS之图片上放置button

    position:relative日常应用的时候通常是设置给position:absolute;的父层的, 父层position:relative; 子层position:absolute;的话, 就 ...

  5. 【SPOJ-GSHOP】Rama and Friends【贪心】【细节】

    题意: 给出n个非严格递增的整数(可能有负数),必须操作k次.每次能够把当中一个数变为它的相反数,使得终于的数列和最大. 输出这个最大和. 考验怎样出坑数据卡自己的程序... #include < ...

  6. OPENWRT中SSH免密钥登陆(具体步骤)

    通过使用ssh-keygen生成公钥,在两台机器之间互相建立新人通道极客. 如果本地机器是client,远程机器为server. 1.使用ssh-keygen生成rsa keygen(在这里会覆盖曾经 ...

  7. Python——异常基础

    异常基础 在Python中,异常会依据错误自己主动地被触发.也能由代码触发和截获.异常由五个语句处理: 1.[try/except]:捕捉由Python或你引起的异常并恢复. 2.[try/final ...

  8. php利用msqli访问数据库并实现分页,

    <?php require_once 'login.php'; $num_rec_per_page=2; // 每页显示数量 //mysql_connect('localhost','jim', ...

  9. 132.try throw catch介绍

    #include <iostream> using namespace std; //try尝试执行,抛出throw,throw之后语句不再执行 //catch处理throw的异常 voi ...

  10. Chrome浏览器查看SSL证书信息

    1.https使用f12打开,选中security 如果F12打不开,可以通过最右端的自定义及控制chrome菜单,打开"更多工具"-->"开发者工具" ...