Can you solve this equation?---hdu2199(二分)

http://acm.hdu.edu.cn/showproblem.php?pid=2199

给出y的值求x;

8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 = Y

x是0到100的实数所以要用二分的方法;

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;
#define N 110
#define INF 0xffffff

int main()
{
    int T,flag;
    double y, m, L, R, Mid;
    scanf("%d", &T);
    while(T--)
    {
        scanf("%lf", &y);
        m=8*pow(100,4)+7*pow(100,3)+2*pow(100,2)+3*100+6;
        if(m<y||y<6)
        {
            printf("No solution!\n");
            continue;
        }
        L=0;R=100;
        while(L<=R)
        {
            Mid=(L+R)/2;
            m=8*pow(Mid,4)+7*pow(Mid,3)+2*pow(Mid,2)+3*Mid+6;
            if(fabs(m-y)<0.0001)
            {
                flag=1;
                break;
            }
            else if(m>y)
            {
                R=Mid;
            }
            else
            {
                L=Mid;
            }
        }
        if(flag==1)
            printf("%.4lf\n", Mid);
        else
            printf("No solution!\n");
    }
    return 0;
}

时间: 2024-08-01 15:09:20

Can you solve this equation?---hdu2199(二分)的相关文章

ACM-二分搜索之Can you solve this equation?——hdu2199

Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7507    Accepted Submission(s): 3490 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?(高精度二分)

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?【二分查找】

解题思路:给出一个方程 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

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 the number of test cases. Then T lines f

hdoj 2199 Can you solve this equation? 【二分枚举】

题意:给出一个数让你求出等于这个数的x 策略:如题.因为整个式子是单调递增的,所以可以用二分. 要注意到精度. 代码: #include <stdio.h> #include <string.h> #include <math.h> #define eps 1e-10 #define f(x) 8*pow(x, 4) + 7*pow(x, 3) + 2*pow(x, 2) + 3*x int main() { int t; double n; scanf("%

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

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

hdoj 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): 12766    Accepted Submission(s): 5696 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