zoukankan      html  css  js  c++  java
  • HDU 2199 Can you solve this equation? 二分

    Can you solve this equation?
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

    Description

    现在,给出等式8* X^4+ 7* X^3+ 2* X^2+ 3 * X +6= Y,请找出他在0和100之间的解(包含0和100)。
    现在,请你试试运气。。。。
     

    Input

    输入的第一行包含一个整数T(1 <= T <=100),表示测试用例的数目。接下来T个数字,每一行都有一个实数Y(abs(Y)<=10^10);

    Output

    对于每个测试用例,如果有解,你应该输出一个实数(精确到小数点后4位,四舍五入),如果在0到100之间无解,就输出“No solution!”。

    Sample Input

    2

    100

    -4 

    Sample Output

    1.6152

    No solution!

    二分水题

    #include <iostream>
    #include <cstdio>
    #include <math.h>
    #include <cstring>
    #include <algorithm>
    #include <iomanip>
    
    using namespace std;
    
    //8* X^4+ 7* X^3+ 2* X^2+ 3 * X +6= Y
    double fx(double x)
    {
        return 8*pow(x,4)+7*pow(x,3)+2*pow(x,2)+3*x+6;
    }
    
    
    int main()
    {
        //freopen("input.txt","r",stdin);
        int t;
        double y;
        cin>>t;
        while(t--)
        {
            cin>>y;
            double l=0;
            double r=100;
            double mid;
            int flag=0;
    
            if(y>=6&&fx(100)>=y)
            {
                while(r-l>1e-8)
                {
                    mid=(r+l)/2;
    
    
                    if(fx(mid)<y)
                    {
                        l=mid;
                    }
                    else
                    {
                        r=mid;
                    }
    
                }
                cout<<fixed<<setprecision(4)<<l<<endl;
            }
            else
                cout<<"No solution!"<<endl;
        }
    }
    

      

  • 相关阅读:
    sqli-labs(二)
    sqli-labs(一)
    路径遍历:ZIP条目覆盖
    JWT
    ActiveMQ漏洞利用方法总结
    Tomcat任意文件上传漏洞CVE-2017-12615
    jsp的文件包含漏洞
    记一次渗透实验(四)
    unity独立游戏开发日志2018/09/22
    python网络编程的坑(持续更新)
  • 原文地址:https://www.cnblogs.com/Hyouka/p/5709418.html
Copyright © 2011-2022 走看看