zoukankan      html  css  js  c++  java
  • 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): 2091    Accepted Submission(s): 1053


    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!
     
     
    View Code
    #include <set>
    #include <map>
    #include <list>
    #include <cmath>
    #include <ctime>
    #include <deque>
    #include <queue>
    #include <stack>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <cctype>
    #include <cstring>
    #include <sstream>
    #include <fstream>
    #include <cstdlib>
    #include <cassert>
    #include <iostream>
    #include <algorithm>

    using namespace std;
    //Constant Declaration
    /*
    --------------------------*/
    //#define LL long long
    #define LL __int64
    const int M=1000000;
    const int INF=1<<30;
    const double EPS = 1e-11;
    const double PI = acos(-1.0);
    /*--------------------------*/
    // some essential funtion
    /*
    ----------------------------------*/
    void Swap(int &a,int &b){ int t=a;a=b;b=t; }
    int Max(int a,int b){ return a>b?a:b; }
    int Min(int a,int b){ return a<b?a:b; }
    int Gcd(int a,int b){ while(b){b ^= a ^=b ^= a %= b;} return a; }
    /*----------------------------------*/
    //for (i = 0; i < n; i++)
    /*
    ----------------------------------*/
    #define F(x) (8*pow(x,4) + 7*pow(x,3) + 2*pow(x,2) + 3*x + 6 - y)

    double y;
    int main()
    {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int t, case1 = 0;
    scanf("%d", &t);
    int n, m;
    int i, j;
    //scanf("%d%d", &n, &m);

    while (t--)
    {
    scanf("%lf", &y);
    if (F(0.0) * F(100.0) > 0)
    {
    puts("No solution!");
    }
    else
    {
    double l = 0, r = 100;
    if (F(l) == 0)
    {
    printf("%.4lf", 0);
    goto end;
    }
    if (F(r) == 0)
    {
    printf("%.4lf", 100);
    goto end;
    }

    double min;
    while (r - l > EPS)
    {
    min = (l + r) / 2;
    if (F(min) == 0)
    {
    goto end;
    }
    if (F(l) * F(min) < 0)
    {
    r = min;
    }
    else
    {
    l = min;//写成l = min + 1就错
    }


    }
    end :
    printf("%.4lf\n", min);




    }
    }

    return 0;
    }
  • 相关阅读:
    node
    github
    [模块] pdf转图片-pdf2image
    python 15 自定义模块 随机数 时间模块
    python 14 装饰器
    python 13 内置函数II 匿名函数 闭包
    python 12 生成器 列表推导式 内置函数I
    python 11 函数名 迭代器
    python 10 形参角度 名称空间 加载顺序
    python 09 函数参数初识
  • 原文地址:https://www.cnblogs.com/qiufeihai/p/2408193.html
Copyright © 2011-2022 走看看