题目链接:

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. STM32 的 printf() 函数串口重定向(HAL库标准库都适用)

    1.建立工程 2.核心:添加新文件usar_fputc.c (名字随便自己命名),把文件添加到项目中去 #include "stdio.h" #include "stm3 ...

  2. react中的跨域问题

    react中的跨域问题

  3. css预编译器——Less的使用

      方法一:仅介绍在客户端环境下使用的方法 1 新建test.less并引入.less该文件(和css一样在head处引入),注意rel="stylesheet/less": &l ...

  4. UVA 11478 Halum

    Halum Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA. Original ID: 114 ...

  5. [Google Guava] 2.2-新集合类型

    转自:并发编程网 原文链接:http://ifeve.com/google-guava-newcollectiontypes/ 链接博客其他文章中还有更多的guava其他功能的描述,有空可慢慢看. G ...

  6. unity3d 延迟运行脚本语句

    在Unity3D中.有yield语句它负责延迟操作,yield return WaitForSeconds(3.0); //等待 3 秒 查看unity3d脚本手冊,使用方法须要在对应的格式. 以下代 ...

  7. Android基础新手教程——1.5.2 Git之使用GitHub搭建远程仓库

    Android基础新手教程--1.5.2 Git之使用GitHub搭建远程仓库 标签(空格分隔): Android基础新手教程 本节引言: 在上一节中.我们学习了怎样使用Git.构建我们的本地仓库.轻 ...

  8. pat(A) 1066. Root of AVL Tree

    代码: #include<iostream> #include<cstdio> #include<cmath> #include<stdlib.h> # ...

  9. shadowOffset 具体解释

    x向右为正,y向下为正 1.y<0 UILabel *label=[[UILabelalloc] initWithFrame:CGRectMake(40,40, 250,50)]; label. ...

  10. sqlite学习笔记9:C语言中使用sqlite之插入数据

    前面创建了一张表,如今给他插入一些数据.插入数据跟创建表差点儿相同,不过SQL语言不一样而已,完整代码例如以下: #include <stdio.h> #include <stdli ...