Simple Function


Time Limit: 2 Seconds       Memory Limit: 32768 KB

Knowing that x can be any real number that x2 + Dx + E ≠ 0. Now, given the following function

y = f(x) =
Ax2 + Bx+ C
-------------------
x2 + Dx + E

What is the range of y.

Input

The first line contains a single integer T (T ≤ 10000), indicating that there are T cases below.

Each case contains five integers in a single line which are values of ABCD and E (-100 ≤ ABCDE ≤ 100).

Output

For each case, output the range of y in the form of standard interval expression like in a single line.

The expression is made up by one interval or union of several disjoint intervals.

Each interval is one of the following four forms: "(a, b)", "(a, b]", "[a, b)", "[a, b]"(there is a single space between ',' and 'b'), where ab are real numbers rounded to 4 decimal places, or "-INF" or "INF" if the value is negative infinity or positive infinity.

If the expression is made up by several disjoint intervals, put the letter 'U' between adjacent intervals. There should be a single space between 'U' and nearby intervals.

In order to make the expression unique, the expression should contain as minimum of intervals as possible and intervals should be listed in increasing order.

See sample output for more detail.

Sample Input

5
1 1 1 2 3
0 1 0 1 -10
-3 -1 0 -1 -1
0 0 0 0 0
1 3 0 2 0

Sample Output

[0.3170, 1.1830]
(-INF, INF)
(-INF, -1.8944] U [-0.1056, INF)
[0.0000, 0.0000]
(-INF, 1.0000) U (1.0000, 1.5000) U (1.5000, INF)
关于求值域,在高中学了很多方法,在这里我不推荐通过移项再根据x来算Δ>=0的方法来求y的值域,我之前就是这样写的,因为这样算出来的Δ值可能有很多种,而且意义不明确(如果数学功底不够就看不出来),太过麻烦,最后讨论分母为0去断点时也很麻烦
下面讲解时修改别人的,因为他的跟我的有点出入。

题目大意:

描述起来很简单,求f(x) = (Ax^2 + Bx + C) / (x^2 + Dx + E)的值域。

解题思路:

分子分母都含有自变量x,不好处理。最简单的想法就是把分子上的自变量消去。(二次->一次->零次)。然后就是各种情况讨论。

1.二次->一次

f(x) =  (Ax^2 + Bx + C) / (x^2 + Dx + E)

=  A + (bx + c) / (x^2 + Dx + E) (其中b=B-A*D, c=C-A*E)

=  A + g(x)

这样我们把分子的二次项消除了。注意之后的结果区间都要加上A。

2.一次-> 零次

(1) 若B = 0。那么g(x) = c / (x^2 + Dx + E)

(a)如果c=0。则值域为[0, 0].

(b)如果c!=0。则此时分母的式子是一个开口向上的抛物线,设其极小值为mins,则取值区间为[mins, INF).

此时需要对mins和c的正负情况讨论才能写出正确区间。(mins的正负即表示Δ)

c>0时

    • mins>0  值域为 (0, c/mins].
    • mins>0  值域为 (0, INF].
    • mins<0  值域为 (-INF, c/mins] U (0, INF)

c<0时同上分析,区间颠倒下就可以了。

(2) 若b != 0。那么g(x) = (bx + c) / (x^2 + Dx + E)

要消去一次项,我们可以换元,令t=b*x + c得到

g(t) = b*b*t / (t^2 + bb*t + cc)   其中bb=D*b-2*c,cc=(c*c+E*b*b-D*b*c);

(1)如果t取0,则g(t)=0;

(2)当t!=0时 g(x) =b*b/(t+cc/t + bb) = h(t)

此时要求h(t)= b*b/(t+cc/t + bb)的值域(t!=0)。只有分母有自变量,非常好求解了。注意最后要把0点补回去。

(i) cc<0 时。t+cc/t 能取遍(-INF, INF)。所以值域的为(-INF, INF)。

(ii) cc>0 时。t+cc/t 的值域为(-INF, 2√cc] U [2√cc, INF)

故分母的值域为(-INF, 2√cc+bb] U [2√cc+bb, INF)

全部的值域易得。我这里不需要讨论分子分母的正负号,但是需要确定区间的范围,细心点就好了,详见代码吧。

#include<stdio.h>
#include<math.h> int main()
{
int T;
double A,B,C,D,E,a,b,c,bb,cc,x1,x2,temp1,temp2,y1,mins;
scanf("%d",&T);
while(T--)
{
scanf("%lf%lf%lf%lf%lf",&A,&B,&C,&D,&E);
a=A;
b=B-A*D;
c=C-A*E;
mins=E-D*D/4;//分母抛物线的极大值
if(b==0)//f(x)=A+((B-A*D)*x+C-A*E)/(x*x+D*x+E),f(x)=a+(b*x+c)/(x*x+D*x+E)
{
if(c==0)
printf("[%.4f, %.4f]\n",A,A);
else if(c>0)
{
if(mins>0)
printf("(%.4f, %.4f]\n",A,c/mins+A);
else if(mins<0)
printf("(-INF, %.4f] U (%.4f, INF)\n",c/mins+A,A);
else printf("(%.4f, INF)\n",A);
}
else
{
if(mins>0)
printf("[%.4f, %.4f)\n",c/mins+A,A);
else if(mins<0)
printf("(-INF, %.4f) U [%.4f, INF)\n",A,c/mins+A);
else printf("(-INF, %.4f)\n",A);
}
}
else //b!=0情况,f(x)=A+b*b/(t+(c*c+E*b*b-D*b*c)/t+D*b-2*c)
{
x1=-c/b;
if(x1*x1+D*x1+E==0)//排除那种分子分母有公因式的情况
{
x2=-D-x1;
if(x1==x2)
printf("(-INF, %.4f) U (%.4f, INF)\n",A,A);
else
{//(b*(x-x1))/((x-x1)*(x-x2))
y1=b/(x1-x2);
if(y1>0)
printf("(-INF, %.4f) U (%.4f, %.4f) U (%.4f, INF)\n",A,A,A+y1,A+y1);
else
printf("(-INF, %.4f) U (%.4f, %.4f) U (%.4f, INF)\n",A+y1,A+y1,A,A);
}
}
else
{
bb=D*b-2*c;
cc=(c*c+E*b*b-D*b*c);
if(cc>0)//分母化成了g(t)=t+cc/t+bb,t=b*x+c,分子变成了b*b,所以不用考虑分子的符号了
{
temp1=2.0*sqrt(cc);
temp2=temp1+bb;//这便是分母的极大值
temp1=-temp1+bb;//分母的极小值
if(temp1>0)//极小值大于0
printf("(-INF, %.4f] U [%.4f, INF)\n",A+b*b/temp2,A+b*b/temp1);
else if(temp1==0)//极小值为0
printf("(-INF, %.4f]\n",A+b*b/temp2);
else if(temp2<0)//极大值小于0
printf("(-INF, %.4f] U [%.4f, INF)\n",A+b*b/temp2,A+b*b/temp1);
else if(temp2==0)//极大值为0
printf("[%.4f, INF)\n",A+b*b/temp1);
else printf("[%.4f, %.4f]\n",A+b*b/temp1,A+b*b/temp2);
}
else if(cc<0)
printf("(-INF, INF)\n");
else
printf("(-INF, INF)\n");
}
}
}
return 0;
}
												

zoj3658 Simple Function (函数值域)的更多相关文章

  1. HDU 4423 Simple Function(数学题,2012长春D题)

    Simple Function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  2. 关于Function()函数对象的那些小九九

    概念:首先,函数是一种特殊类型的数据,函数也是数据类型的一种,实际上函数也是一种对象,函数对象的内建构造器是Function(); 函数的几种创建方式: 函数声明法: function sum(a,b ...

  3. JavaScript function函数种类(转)

    转自:http://www.cnblogs.com/polk6/p/3284839.html JavaScript function函数种类 本篇主要介绍普通函数.匿名函数.闭包函数 目录 1. 普通 ...

  4. JavaScript function函数种类介绍

    JavaScript function函数种类介绍 本篇主要介绍普通函数.匿名函数.闭包函数 1.普通函数介绍 1.1 示例 ? 1 2 3 function ShowName(name) {     ...

  5. 【JS学习笔记】关于function函数

    函数的基本格式 function 函数名() { 代码: } 函数的定义和调用 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transit ...

  6. 2019-2-14SQLserver中function函数和存储过程、触发器、CURSOR

    Sqlserver 自定义函数 Function使用介绍 前言:         在SQL server中不仅可以可以使用系统自带的函数(时间函数.聚合函数.字符串函数等等),还可以根据需要自定义函数 ...

  7. 创建一个Scalar-valued Function函数来实现LastIndexOf

    昨天有帮助网友解决的个字符串截取的问题,<截取字符串中最后一个中文词语(MS SQL)>http://www.cnblogs.com/insus/p/7883606.html 虽然实现了, ...

  8. javascript:function 函数声明和函数表达式 详解

    函数声明(缩写为FD)是这样一种函数: 有一个特定的名称 在源码中的位置:要么处于程序级(Program level),要么处于其它函数的主体(FunctionBody)中 在进入上下文阶段创建 影响 ...

  9. jquery中的 $(function(){ .. }) 函数

    2017-04-29 在讲解jquery中的 $(function(){ .. }) 函数之前,我们先简单了解下匿名函数.匿名函数的形式为:(function(){ ... }),又如 functio ...

随机推荐

  1. Linux shell入门基础(一)

    Linux shell入门基础(一): 01.增加删除用户: #useradd byf   userdel byf(主目录未删除)  userdel -r byf   该用户的属性:usermod 用 ...

  2. await, anync

    public Form1() { InitializeComponent(); } // The following method runs asynchronously. The UI thread ...

  3. javascript高级特性(面向对象)

    javascript高级特性(面向对象): * 面向对象: * 面向对象和面向过程的区别: * 面向对象:人就是对象,年龄\性别就是属性,出生\上学\结婚就是方法. * 面向过程:人出生.上学.工作. ...

  4. java transient关键字和transaction的区别

    transient:表示临时的,不会被持久化,保存进数据库 transaction:表示事务 <div style="background: #fff; color: #0ff;&qu ...

  5. tabpagerindictor:mergeReleaseResources FAILED Error:Execution failed for task ':tabpagerindictor:mergeReleaseResources'. > D:\android\adt-bundle-windows-x86_64-20140702\android-open-project-demo-mast

    解决:将项目移动到路径少的目录再运行即可 异常日志: D:\android\adt-bundle-windows-x86_64-20140702\android-open-project-demo-m ...

  6. ImageView设置点击效果没有用?ImageView src的图片大小改变不了?

    ImageView设置点击效果没有用? 解决 1.ImageView xml里面必须clickable 和longClickable为true <ImageView android:layout ...

  7. 如何分析apache日志[access_log(访问日志)和error_log(错误日志)]

    如何分析apache日志[access_log(访问日志)和error_log(错误日志)] 发布时间: 2013-12-17 浏览次数:205 分类: 服务器 默认Apache运行会access_l ...

  8. PL/SQL中的变量案例解析

    1.标量: ag1: declare v_ename emp.ename%type;--自己称为单变量 begin select ename into v_ename from emp where e ...

  9. 接入淘宝SDK(OneSDK)和支付宝SDK(AlipaySDK)出现 duplicate symbols for architecture i386

    起初我在我的项目中先接入了AlipaySDK,没有出现什么问题,之后想要接入淘宝SDK之后,就出现了duplicate symbols for architecture i386的错误 经过一段时间排 ...

  10. C/C++中的++a和a++

    代码: #include <iostream> #include <cstdio> using namespace std; int main(){ ; (++a)+=a; / ...