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): 5999    Accepted Submission(s): 2828


    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:  2289 2298 2141 3400 1969 
     
     1 //15MS    248K    537 B    C++    
     2 /*
     3     
     4     题意:
     5         给出一条公式:
     6              8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y
     7         和Y的值,要求你在(0,100)的范围内求4位小数精确解
     8     
     9     二分法:
    10         先排除无解的情况,因为函数在(0,100)单调递增,最小值为6,
    11     最大值为fac(100),先排除无解情况然后用二分法计算
    12          
    13 */
    14 #include<stdio.h>
    15 #define e 1e-7
    16 double fac(double a)
    17 {
    18     return (8*a*a*a*a+7*a*a*a+2*a*a+3*a+6);
    19 }
    20 int main(void)
    21 {
    22     int t;
    23     double n;
    24     scanf("%d",&t);
    25     while(t--)
    26     {
    27         scanf("%lf",&n);
    28         if(n<6 || n>fac(100)){
    29             puts("No solution!");continue;
    30         }
    31         double l=0;
    32         double r=100;
    33         while(r-l>e){
    34             double mid=(l+r)/2;
    35             if(fac(mid)>n) r=mid;
    36             else l=mid;
    37         }
    38         printf("%.4lf
    ",r);
    39     }
    40     return 0;
    41 }

    color: #800080;

  • 相关阅读:
    Python-Matplotlib 12 多图figure
    Python-Matplotlib 11 子图-subplot
    Python Day16
    Python Day15
    Python Day13-14
    Python Day12
    Python Day11
    Python Day9-10
    Python Day8
    Python Day8
  • 原文地址:https://www.cnblogs.com/GO-NO-1/p/3426040.html
Copyright © 2011-2022 走看看