Hdoj 2199 HDU 2199 can you solve this equation? ACM 2199 in HDU

Source: Internet
Author: User
Miyu original, post Please note: Reprinted from __________ White House

Question address:
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2199
Description:
Can you solveThisEquation?

Time limit:2000/1000MS (Java/Others) memory limit:32768/32768K (Java/Others)
Total submission (s ):322Accepted submission (s ):148

Problem description
Now, given the equation8 * X ^ 4   +   7 * X ^ 3   +   2 * X ^ 2   +   3 * X +   6   = Y, can you find its solution 0 And 100 ;
Now please Try Your lucky.
 

Input
The first line of the input contains an integer T (1<=T<=100) Which means the number of test cases. Then T lines follow, each line has a real number y (FABS (y)<=1e10 );
 

Output
For each test Case , You shoshould just output one real number (accurate up 4   Decimal Places), which Is The solution of the equation, or "no solution ! ", If There Is No solution For The equation 0 And 100 .
 

Sample Input
2
100
-4
 

Sample output
1.6152
No solution!

Question Analysis: Obviously, this is a 2-point search question, but pay attention to the data of the next question !! The real number of 1e10 !! And the precision is 0.0001, so even if the data size is 2 points
Is it a pity that the usual recursive method is... re... no way, it can only loop.
The following is the recursive reCode:

# Include <iostream> # include <cmath> Using namespace STD ; # Define POW (x) * (x) # define pow3 (x) (POW (x) * (x) # define pow4 (X) (POW (x) * POW (x )) Double Y = 0 ;  Bool Doueql ( Double A ,  Double B ){  If  ( FABS ( A - B ) <= 1e-6 )  Return True ;  Return False ;}  Double Cal (  Double N ){  Return 8.0 * Pow4 ( N) + 7 * Pow3 ( N ) + 2 * POW ( N ) + 3 * N + 6 ;}  Double Bisearch (  Double L ,  Double R ){  If  ( Doueql ( L , R )){ If  ( Doueql ( Y , Cal ( L )))  Return L ;  Return  - 1 ;}  Double Mid = ( L + R )/ 2.0 ;  If  ( Doueql ( Y , Cal ( Mid)))  Return Mid ;  Else if  ( Cal ( Mid )> Y )  Return Bisearch ( L , Mid - 0.0001 );  Elsereturn Bisearch ( Mid + 0.0001 , R );}  Int  Main  (){ Int T ; Scanf ( "% D" ,& T );  While  ( T --){ Scanf ( "% Lf" ,& Y );  If  ( Cal ( 0 )> = Y && Cal ( 100 ) <= Y ){ Printf ( "No solution! \ N" );  Continue  ;}  Double Res = Bisearch ( 0.0 , 100.0 );  If  ( Res =- 1 ) Printf ( "No solution! \ N" );  Else Printf ( "%. 4lf \ n" , Res );}  Return 0 ;} 

The AC code is as follows:Miyu original, post Please note: Reprinted from__________ White House

# Include < Iostream >
# Include < Cmath >
Using   Namespace STD;
# Define Pow (x) * (x ))
# Define Pow3 (x) (POW (x) * (x ))
# Define Pow4 (x) (POW (x) * POW (x ))
Double Y =   0 ;
Double Cal ( Double N)
{
Return   8.0   * Pow4 (N) +   7   * Pow3 (N) +   2   * Pow (N) +   3   * N +   6 ;
}
Int Main ()
{
Int T;
Scanf ( " % D " , & T );
While (T -- )
{
Scanf ( " % Lf " , & Y );
If (CAL ( 0 ) > Y | Cal ( 100 ) < Y)
{
Printf ( " No solution! \ N " );
Continue ;
}
Double L =   0.0 , R =   100.0 , Res =   0.0 ;
While (R - L > 1e - 6 )
{
Double Mid = (L + R) /   2.0 ;
Res = Cal (MID );
If (Res > Y)
R = Mid - 1e - 6 ;
Else  
L = Mid + 1e - 6 ;
}
Printf ( " %. 4lf \ n " , (L + R) /   2.0 );
}
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.