• ACM: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): 16281    Accepted Submission(s): 7206
    
    
    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
     

    数学题,直接二分,代码

     1 #include"iostream"
     2 #include"algorithm"
     3 #include"cstdio"
     4 #include"cstring"
     5 #include"cmath"
     6 #define max(a,b) a>b?a:b
     7 #define min(a,b) a<b?a:b
     8 #define MX 10000 + 50
     9 using namespace std;
    10 
    11 double f(double x)
    12 {
    13     return  8*pow(x,4)+7*pow(x,3)+2*pow(x,2)+3*x+6;
    14 }
    15 
    16 int main()
    17 {
    18     int n;
    19     double m;
    20     while(~scanf("%d",&n))
    21     {
    22         for(int k=1; k<=n; k++)
    23         {
    24             scanf("%lf",&m);
    25 
    26             double i=0.0;
    27             if(m<f(0)||m>f(100))
    28             {
    29                 printf("No solution!
    ");continue;
    30             }
    31             double fr=0.0,ed=100.0;
    32             for(; fabs(f(fr)-f(ed))>1e-4;)
    33             {
    34                 i=(fr+ed)/2;
    35                 if(f(i)<m)fr=i;
    36                 else ed=i;
    37             }
    38             {
    39                 printf("%.4lf
    ",i);
    40             }
    41         }
    42     }
    43     return 0;
    44 }
    View Code
  • 相关阅读:
    Tomcat临时目录及java.io.tmpdir对应的目录
    第一篇随笔
    面试
    近期小结-082714
    从头开始构建web前端应用——字符炸弹小游戏(一)
    web版ppt制作插件impress.js源码注释翻译
    .net web service Application_BeginRequest,记录请求数据
    微信APP支付,阿里云服务器,统一下单请求超时
    android仿ios圆弧边框背景
    google map 地址编码及反向地址编码
  • 原文地址:https://www.cnblogs.com/HDMaxfun/p/5693729.html
Copyright © 2020-2023  润新知