zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    session的生命周期
    临远的spring security教程
    spring security原理图及其解释
    解决eclipse中出现Resource is out of sync with the file system问题
    从SOA到BFV【普元的一份广告文章】
    普元OA平台介绍
    门户平台
    企业门户平台解决方案
    使用 CAS 在 Tomcat 中实现单点登录
    CAS 跨域原理
  • 原文地址:https://www.cnblogs.com/HDMaxfun/p/5693729.html
Copyright © 2011-2022 走看看