• HDU 2199 Can you solve this equation? 【浮点数二分求方程解】


    Now,given the equation 8x^4 + 7x^3 + 2x^2 + 3x + 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!

    #include<cstdio>
    #include<string>
    #include<cstdlib>
    #include<cmath>
    #include<iostream>
    #include<cstring>
    #include<set>
    #include<queue>
    #include<algorithm>
    #include<vector>
    #include<map>
    #include<cctype>
    #include<stack>
    #include<sstream>
    #include<list>
    #include<assert.h>
    #include<bitset>
    #include<numeric>
    #define debug() puts("++++")
    #define gcd(a,b) __gcd(a,b)
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define fi first
    #define se second
    #define pb push_back
    #define sqr(x) ((x)*(x))
    #define ms(a,b) memset(a,b,sizeof(a))
    #define sz size()
    #define be begin()
    #define pu push_up
    #define pd push_down
    #define cl clear()
    #define lowbit(x) -x&x
    #define all 1,n,1
    #define rep(i,x,n) for(int i=(x); i<(n); i++)
    #define in freopen("in.in","r",stdin)
    #define out freopen("out.out","w",stdout)
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ULL;
    typedef pair<int,int> P;
    const int INF = 0x3f3f3f3f;
    const ll LNF = 1e18;
    const int maxn = 1e3 + 20;
    const int maxm = 1e6 + 10;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int dx[] = {-1,1,0,0,1,1,-1,-1};
    const int dy[] = {0,0,1,-1,1,-1,1,-1};
    int dir[4][2] = {{0,1},{0,-1},{-1,0},{1,0}};
    const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    ll quickpow(ll a, ll b) {
        ll ans = 0;
        while (b > 0) {
            if (b % 2)ans = ans * a;
            b = b / 2;
            a = a * a;
        }
        return ans;
    }
    int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a%b);
    }
    bool cmp(int a, int b) {
        return a > b;
    }
    int T;
    double y;
    double ok(double x)
    {
        return 8*pow(x,4)+7*pow(x,3)+2*pow(x,2)+3*x+6;
    }
    int main()
    {
        scanf("%d",&T);
        while(T--)
        {
            int f=0;
            scanf("%lf",&y);
             if(ok(0)>y||ok(100)<y)
             {
                printf("No solution!
    ");
                continue;
             }
            //int cas = 100;
            double l = 0, r = 100.0;
            while(r-l>eps)
            {
                double mid = (l+r)/2.0;
                if(ok(mid)>y)
                {
                   r=mid;
                }
                else l=mid;
            }
            printf("%.4f
    ",l);
        }
    }
    
    
  • 相关阅读:
    开源博客平台WordPress十岁啦!
    (转载)C# Attribute 用法备忘
    hibernate入门
    Hibernate对象关系映射基础
    struts2UI标签
    struts2文件上传2(多文件)
    struts2验证(手工)
    通过修改注册表改变txt文件的默认打开方式
    struts2验证(XML)
    Struts国际化
  • 原文地址:https://www.cnblogs.com/Roni-i/p/9358302.html
Copyright © 2020-2023  润新知