zoukankan      html  css  js  c++  java
  • hdu 2199 Can you solve this equation? 二分

    Can you solve this equation?

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 6763    Accepted Submission(s): 3154


    Problem Description
    Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,can you find its solution between 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 should just output one real number(accurate up to 4 decimal places),which is the solution of the equation,or “No solution!”,if there is no solution for the equation between 0 and 100.
     
    Sample Input
    2
    100 -4
     
    Sample Output
    1.6152
    No solution!
     
    Author
    Redow
     
    Recommend
    lcy   |   We have carefully selected several similar problems for you:  2899 2289 2298 2141 3400 
     
     
     1 /*
     2 对于精度,我表示囧。
     3 我以为,保留4位小数,就到1e-5就可以了。
     4 
     5 */
     6 
     7 #include<iostream>
     8 #include<stdio.h>
     9 #include<cstring>
    10 #include<cstdlib>
    11 #include<math.h>
    12 using namespace std;
    13 
    14 double fun(double x)
    15 {
    16     return 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6;
    17 }
    18 void EF(double l,double r,double Y)
    19 {
    20     double mid;
    21     while(r-l>1e-7)
    22     {
    23         mid=(l+r)/2;
    24         double ans=fun(mid);
    25         if( ans >Y )
    26             r=mid-1e-8;
    27         else l=mid+1e-8;
    28     }
    29     printf("%.4lf
    ",(l+r)/2);
    30 }
    31 int main()
    32 {
    33     int T;
    34     double Y;
    35     scanf("%d",&T);
    36     {
    37         while(T--)
    38         {
    39             scanf("%lf",&Y);
    40             if( fun(0.0)>Y || fun(100.0)<Y)
    41                 printf("No solution!
    ");
    42             else
    43                  EF(0.0,100.0,Y);
    44         }
    45     }
    46     return 0;
    47 }
  • 相关阅读:
    使用递归输出某个目录下所有子目录和文件
    如何进行复杂度分析?
    什么是时间复杂度?什么是空间复杂度?
    什么是复杂度?为什么要进行复杂度分析?
    什么是递归?递归的优缺点是什么?
    Executor 如何使用?
    什么是spring boot?为什么要用?
    spring boot核心配置文件是什么?
    @Autowired的作用是什么?
    @RequestMapping的作用是什么?
  • 原文地址:https://www.cnblogs.com/tom987690183/p/3561350.html
Copyright © 2011-2022 走看看