Zoj3658 Simple Function (Function value range)

Source: Internet
Author: User

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 A, B, C, D and E (-100 ≤a, B, C, D, E ≤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)", "[, b] "(there is a single space between ',' and 'B'), where a, B 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 shoshould be a single space between 'U' and nearby intervals.

In order to make the expression unique, the expression shoshould contain as minimum of intervals as possible and intervals shoshould 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) has learned many ways to evaluate the value range, here, I do not recommend you calculate the value range of y by moving the item and then calculating the value of Delta> = 0 based on x. I wrote it like this before, it is too troublesome because the Delta value calculated in this way may have many types of values with unclear meanings (if the mathematical skills are not enough, it cannot be seen, finally, when the denominator is 0, it is very difficult to modify others during the next explanation, because it is a little different from mine. The description is very simple. Calculate the value range of f (x) = (Ax ^ 2 + Bx + C)/(x ^ 2 + Dx + E. Solution: the numerator denominator contains the independent variable x, which is difficult to solve. The simplest idea is to remove the independent variables on the numerator. (Secondary> once> zero ). Then we will discuss various situations. 1. secondary-> once f (x) = (Ax ^ 2 + Bx + C)/(x ^ 2 + Dx + E) = A + (bx + c) /(x ^ 2 + Dx + E) (where B = B-A * D, c = C-A * E) = A + g (x) in this way, we have eliminated the secondary item of the numerator. Note that A must be added to all subsequent result ranges. 2. Once-> zero (1) if B = 0. Then g (x) = c/(x ^ 2 + Dx + E) (a) If c = 0. The value range is [0, 0]. (B) If c! = 0. In this case, the denominator is an open-up parabolic curve. If the minimum value is mins, the value range is [mins, INF ). in this case, we need to discuss the positive and negative situations of mins and c to write the correct interval. (Positive and negative values of mins indicate △) when c> 0, the value of mins> 0 is (0, c/mins]. mins> 0 value range is (0, INF]. when the mins <0 value range is (-INF, c/mins] U (0, INF) c <0, the above is analyzed, and the interval can be reversed. (2) If B! = 0. So g (x) = (bx + c)/(x ^ 2 + Dx + E) to delete an item, we can change the yuan, let t = B * x + c get g (t) = B * t/(t ^ 2 + bb * t + cc) where bb = D * B-2 * c, cc = (c * c + E * B-D * B * c); (1) if t is 0, g (t) = 0; (2) when t! = 0, g (x) = B * B/(t + cc/t + bb) = h (t). h (t) is required) = B * B/(t + cc/t + bb) value range (t! = 0 ). Only the denominator has independent variables, which is a good solution. Note that you must add 0 to the end. (I) cc <0. T + cc/t can be retrieved (-INF, INF ). Therefore, the value range is (-INF, INF ). (Ii) cc> 0. The value of t + cc/t is (-INF, 2 √ cc] U [2 √ cc, INF), so the value of the denominator is (-INF, 2 √ cc + bb] U [2 √ cc + bb, INF. I don't need to discuss the positive and negative numbers of the denominator here, but I need to determine the range. Just be careful. For details, see the code.

# 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", &, & B, & C, & D, & E); a = A; B = B-A * D; c = C-A * E; mins = E-D * D/4; // maximum value of the denominator parabolic 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/min S + 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-D * B * c) /t + D * B-2 * c) {x1 =-c/B; if (x1 * x1 + D * x1 + E = 0) // exclude the case where the numerator denominator has a common expression {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 + 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-D * B * c); if (cc> 0) // the denominator is converted into g (t) = t + cc/t + bb, t = B * x + c, the molecule becomes B * B, therefore, you do not need to consider the molecular symbols {temp1 = 2.0 * sqrt (cc); temp2 = temp1 + bb; // This is the maximum value of the denominator temp1 =-temp1 + bb; // The minimum value of the denominator if (temp1> 0) // the minimum value is greater than 0 printf ("(-INF, %. 4f] U [%. 4f, INF) \ n ", A + B * B/temp2, A + B * B/temp1); else if (temp1 = 0) // The minimum value is 0 printf ("(-INF, %. 4f] \ n ", A + B * B/temp2); else if (temp2 <0) // The maximum value is less than 0 printf (" (-INF, %. 4f] U [%. 4f, INF) \ n ", A + B * B/temp2, A + B * B/temp1); else if (temp2 = 0) // The maximum value is 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 ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.