zoukankan      html  css  js  c++  java
  • 杭电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): 12798    Accepted Submission(s): 5716


    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 #include <cmath>
     2 #include <cstdio>
     3 #include <iostream>
     4 using namespace std;
     5 double f(double x)
     6 {
     7     return 8*x*x*x*x + 7*x*x*x + 2*x*x + 3*x + 6;
     8 } 
     9 int main()
    10 {
    11     int t; double y, mid;
    12     scanf("%d", &t);
    13     while(t--)
    14     {
    15         scanf("%lf", &y);
    16         if(y<f(0) || y>f(100))
    17         {
    18             printf("No solution!
    ");
    19             continue;
    20         }
    21         double left=0.0, right = 100.0;
    22         while(right - left > 1e-8)
    23         {
    24              mid = (right + left) / 2.0;
    25             if(abs(abs(f(mid))-y) < 1e-6)
    26             break;
    27             if(f(mid) < y) left = mid;
    28             else right = mid;
    29         }
    30         printf("%.4lf
    ", mid);
    31             
    32     }
    33     return 0;
    34 }
  • 相关阅读:
    align 的用法
    layui 验证用法
    C# Post请求方法
    SQL 查询今天、昨天、7天内、30天的数据
    对Dijkstra名字发音的看法
    Ubuntu桌面图标消失且右键失效的解决办法
    Ubuntu下安装与配置Matlab
    ns 简单网络模拟
    JAVA包含第三方包的部署方法
    Ubuntu下配置ftp服务端
  • 原文地址:https://www.cnblogs.com/soTired/p/4688788.html
Copyright © 2011-2022 走看看