hdu Can you solve this equation?

本题是一道二分的题,核心就是mi的大小,即精度的取值。因为原函数是一个单调递增的函数,所以可以确定y的取值范围,并且在范围内的每一个y的值,一定至少存在一个x与其对应。刚开始我将取二分这个环节用一个函数来表示的,但是返回值始终是一个随机值,实在是搞不懂,无奈之下只能将那个步骤直接写在主函数内。。。

#include"iostream"
#include"stdio.h"
#include"algorithm"
#include"string.h"
#include"cmath"
#define mi 1e-8
using namespace std;
double cf(double x)
{
    return 8*x*x*x*x + 7*x*x*x + 2*x*x + 3*x + 6;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        double y;
        cin>>y;
        if(y<6 || y>807020306)
        {
            printf("No solution!\n");
            continue;
        }
       double x1=0.0,x2=100.0;
       while(x2-x1>mi)
       {
           double x=(x2+x1)/2.0;
           if(cf(x)>y) x2=x;
           else x1=x;
       }
        printf("%.4lf\n",x1);
    }
    return 0;
}

时间: 2024-11-03 03:33:07

hdu Can you solve this equation?的相关文章

hdu 2199 Can you solve this equation?(高精度二分)

http://acm.hdu.edu.cn/howproblem.php?pid=2199 Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 13468    Accepted Submission(s): 6006 Problem Description Now,given the

hdu 2199 Can you solve this equation?

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2199 题目大意:找到满足8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y的x值,注意精确度问题. 1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 5 using namespace std; 6 7 8 double fun(double s) 9 { 10 return

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): 7493    Accepted Submission(s): 3484 Problem Description Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,

HDU 2199 Can you solve this equation?(二分精度)

HDU 2199 Can you solve this equation? 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. InputThe first line of the input contains an integer T(1<=T<=100) which means t

HDU 2199 Can you solve this equation?【二分查找】

解题思路:给出一个方程 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,求方程的解. 首先判断方程是否有解,因为该函数在实数范围内是连续的,所以只需使y的值满足f(0)<=y<=f(100),就一定能找到该方程的解,否则就无解. 然后是求解过程, 假设一个区间[a,b],mid=(a+b)/2,如果f(a)*f(b)<0,那么函数f(x)在区间[a,b]至少存在一个零点,如果f(a)<0,说明0点在其右侧,那么将a的值更新为当前mid的值,如果f(a)&g

ACM: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): 16281 Accepted Submission(s): 7206 Problem Description Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,can

杭电 HDU ACM 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): 11180    Accepted Submission(s): 5151 Problem Description Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 ==

(hdu step 4.1.1)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): 915 Accepted Submission(s): 436   Problem Description Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,c

HDU 搜索练习 Can you solve this equation?

Can you solve this equation? Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 186 Accepted Submission(s) : 59 Problem Description Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,can you