zoukankan      html  css  js  c++  java
  • hdu 2199 二分搜索

    Can you solve this equation?

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


    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!

    注意控制精度,不然会超时,虽然是保留四位小数,但是精度得10的-8次方左右

     1 #include<iostream>
     2 #include<stdio.h>
     3 #define exp 1e-8
     4 using namespace std;
     5 
     6 double key;
     7 
     8 double Binary(double low,double high)
     9 {
    10     while(high-low>exp)
    11     {
    12         double mid = (low+high)/2;
    13         if(8*mid*mid*mid*mid + 7*mid*mid*mid + 2*mid*mid + 3*mid + 6 > key)
    14             high=mid-exp;
    15         else
    16             low=mid+exp;
    17     }
    18     return low;
    19 }
    20 int main()
    21 {
    22     int t;
    23     scanf("%d",&t);
    24     while(t--)
    25     {
    26         scanf("%lf",&key);
    27         if(6>key || 8*100*100*100*100 + 7*100*100*100 + 2*100*100 + 3*100 + 6 < key)
    28             printf("No solution!
    ");
    29         else
    30             printf("%.4f
    ",Binary(0, 100));
    31     }
    32     return 0;
    33 }
  • 相关阅读:
    WEB测试总结 (架构,设计)精华部分(转)
    javascript的拖放入门
    javascript十个最常用的自定义函数 (转)
    common.css
    c#中DateTime类
    PHP网站开发方案实例
    PHP框架 DooPHP 1.2 发布
    0 WINDOWS系统 + Apache +PHP5 +Zend + MySQL + phpMyAdmin安装方法(视频教程)
    IE8 CSS兼容性记录(转)
    在网站测试中如何做好安全性测试
  • 原文地址:https://www.cnblogs.com/Xycdada/p/6711489.html
Copyright © 2011-2022 走看看