zoukankan      html  css  js  c++  java
  • HDU 2199 Can you solve this equation?(水题吗?!)

    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!

    题意:输入y的值,则求出方程8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y的解,若有解,则该解一定在[0, 100]之间,输出x,若无解则输出No solution!。

    #include<stdio.h>
    #include<math.h>
    int main ()
    {
        double a, b, c, y, sum, d;
        int T, x;
    
        scanf("%d", &T);
    
        while (T--)
        {
            scanf("%lf", &y);
    
            x = 0;
            a = 0;
            b = 100;
    
            d = 8*b*b*b*b + 7*b*b*b + 2*b*b + 3*b + 6;
            c = 8*a*a*a*a + 7*a*a*a + 2*a*a + 3*a + 6;
    
            if (y >= c && y <= d)
                x = 1;
            if (x)
            {
                while (b-a > 1e-6) ///浮点数判断b是否大于a
                {
                    c = (a+b)/2;
                    sum = 8*c*c*c*c + 7*c*c*c + 2*c*c + 3*c + 6;
    
                    if (sum > y)
                        b = c-1e-7;
                    else
                        a = c+1e-7;
                }
    
                printf("%.4lf
    ", (a+b)/2);
            }
    
            if (x == 0) printf("No solution!
    ");
        }
    
        return 0;
    }
  • 相关阅读:
    ros 编译指定包
    TCP_IP Sockets编程C语言实现第2版 源码下载
    python 文件,文件夹,路径操作
    python 导入包
    ImportError: No module named rospy
    python安装simplejson
    EditPlus 中添加 Win32 ASM 语法支持
    程序设计学习与试验系统下载
    masm for windows2015 下载安装
    dosbox+masm汇编环境的安装和使用
  • 原文地址:https://www.cnblogs.com/syhandll/p/4780909.html
Copyright © 2011-2022 走看看